Column contains NULL data

  • Thread starter Thread starter DaveF
  • Start date Start date
D

DaveF

dr.GetString(2) is Null how do I deal with that?

Line 72: Do While dr.Read
Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
Line 74: Loop
 
dr.GetString(2) is Null how do I deal with that?

Line 72: Do While dr.Read
Line 73: aString = aString + CStr(dr.GetValue(0)) + ":" &
dr.GetString(1) + ":" & dr.GetString(2) + ":" + dr.GetString(3) + ":"
Line 74: Loop

You have to manually check the case that it is DbNull.Value. I usually
create a StringUtil class w/ static methods that do stuff like this ()

Public Static Function StringUtil.ToString(val as object) as string
if ((val = DbNull.value) orelse (val = null)) Then
return String.empty
else
return val.ToString()
end if
end function

sorry, haven't done vb.net in awhile, so use as a guideline...
 
Or you could just do a ToString on it....Intellisense won't work but
it will convert DBnull values to "".
 
Back
Top