Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct way to test for Null values?

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
hey guys,

OK, I've been beating my head on my desk trying to figure this out, and its driving me nuts!!!

Consider the following:

If .Item(3) Is Null Then
Return 0
Else
Return 1
End If

Now, in vb6 I know this would work, but now in .NET it doesn't due to DBNull or whatever they use. Problem is, I can't find anything describing HOW to use it. For instance, do I:
a) test for nothing? If .Item(3) Is Nothing Then...
I've tried this, but couldn't get it to work
b) test for dbnull? If .Item(3) Is DBNull Then...
This also craps out.
c) Create a variable of type dbnull and test against taht?
Dim r as DBNull
If .Item(3) IS r Then...
but that doesn't seem to work either

AAARRRGGGHHHH!!!!! Can someone please explain?

Thanks,
Jack
 
heh, nevermind...Is DBNull seemed to work this time around for me.
;)

sigh...I can breathe easier now...

Thanks guys,

jack
 
what syntax did you use for the test? when I use Is DBNull, I get "Object cannot be cast from DBNULL to other types"...???

thanks!
sheri
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top