Friday, March 23, 2012

Problem in checking null record

Hello,

I am using sql server 2000 as my backend.

If there is any null record in my table , I am getting following error:

***********

Conversion from type 'DBNull' to type 'String' is not valid.

**************

to overcome this error I want to check if its null then don't do anything else do something.

I have tried like this:

If rs.fields("ph").value="NULL" then

else

.......

....

...

end if

But this does not solve my problem.

Please help me i anyone can.

Thanks.

If rs.fields("ph") Is DbNull.Value Then
'it's null
Else
'it can be converted to a string
End If

Your solution test to see if the field = "NULL". Because you have NULL in quotes, you are actually testing to see if the field holds a string wiht the letters N U L L in it. The other thing about NULL is that nothing can equal null. Null means "unknown value", so it is impossible to compare one unknown value with another, because, well, they are unknown... The test for null is IsNull.

No comments:

Post a Comment