Column contains NULL data

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
 
S

S. Justin Gengo

Dave,

If Not dr.GetString(2) Is System.DBNull.Value Then

End If

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
C

Craig Deelsnyder

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...
 
L

LOSER

Or you could just do a ToString on it....Intellisense won't work but
it will convert DBnull values to "".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top