Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Handling Null Value

Author  Topic 

vk18
Posting Yak Master

146 Posts

Posted - 2008-02-05 : 18:02:36
Hi Guys,

I am using datareader and i have a null value in one of the Time Field. Is DBnull.value is not working, Any idea
Thx

If dbreader("timeactual") Is DBNull.Value then
timeactual = ""
Else
timeactual = dbreader("timeactual")
End If

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-02-05 : 18:32:58
What isn't working? What is happening,and what do you want to have happen?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

vk18
Posting Yak Master

146 Posts

Posted - 2008-02-05 : 18:45:46
quote:
Originally posted by jsmith8858

What isn't working? What is happening,and what do you want to have happen?

- Jeff
http://weblogs.sqlteam.com/JeffS




I am getting an Error as " Thread is being aborted" i have a null value in that field, If it is null then i want to make that value as empty. Any Idea?
Thx
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-02-05 : 18:50:40
On what line is the error? what datatype is timeactual, both the variable in your code and also the column in your table? you can't return a STRING in one case ("") and a datetime value in another if you are using proper data types at your client without casting and/or converting.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-02-06 : 15:16:13
quote:
Originally posted by vk18

Hi Guys,

I am using datareader and i have a null value in one of the Time Field. Is DBnull.value is not working, Any idea
Thx

If dbreader("timeactual") Is DBNull.Value then
timeactual = ""
Else
timeactual = dbreader("timeactual")
End If



Try this:

If Not IsDBNull(dbreader("timeactual")) Then
timeactual = CType(dbreader("timeactual"), Type)
End If

You also shouldn't use = '' use = String.Empty


Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-02-06 : 15:56:22
quote:
Originally posted by jhermiz

quote:
Originally posted by vk18

Hi Guys,

I am using datareader and i have a null value in one of the Time Field. Is DBnull.value is not working, Any idea
Thx

If dbreader("timeactual") Is DBNull.Value then
timeactual = ""
Else
timeactual = dbreader("timeactual")
End If



Try this:

If Not IsDBNull(dbreader("timeactual")) Then
timeactual = CType(dbreader("timeactual"), Type)
End If

You also shouldn't use = '' use = String.Empty


Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]



You also didnt state what timeactual is. If you are assigning to some text box you need to cast the dbreader timeactual value to a string and assign it to the .Text property of the text box. Also note that you need to input the Type in the CType call I posted above. Just place the type of casting you'd like to be applied.

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
   

- Advertisement -