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!

asp.net handle field that has null value 1

Status
Not open for further replies.

maswien

Technical User
Sep 24, 2003
1,286
CA

I have a piece of code to test if the return column is null:

If Not objDataReader.GetString(2) Is DBNull.Value Then
...

end if

I got error tells me that the cast is not valid!


What's the correct way to test null?


Thanks
 
Try using something like below...

If Not IsDBNull(objDataReader.GetString(2)) Then
...
End If

Jignasu
 

It doesn't work eithor, the same error.

Actually the value for objDataReader.GetString(2) is a '' but not a null in the database, in any case above statement shouldn't fail. it's so weird!

 
Instead of objDataReader.GetString(2), use objDataReader.Item(2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top