Monday, March 12, 2012

How to handle DBNull

As i write some functions to return string or dataset from database, there is a chance of return DBNULL.

Even i checked the dr(0) with Nothing, It still get Error
dim dr as sqldatareader = xxx.executeQuery
if dr.Read() then
if dr(0) <> Nothing Then
dim abc as string = dr(0)
end if
end if

How can i solve this?
Thx a lotsThere is ISDBNull function in VB and also isDBNull method in SqldataReader, which you can use to check if field is null. If field is null (DBNull), you should set the member/variable you set based on this field, so that its value clearly indicates it has not been set, for example with string it could be String.Empty.
thx for your quick respone

Labels: , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home