Using SQL DataReaders Efficiently

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my SQL database, I have a "text" column type that can contain null values.
I want to loop thru my data using a sqldatareader and store the value in net
string variable. How would I check the sqldatareader value for null prior to
attemping the assignment to my net string variable. Also, if the read value
is null, do I want to assign my net sting variable to "" or is there some
more efficent way to deal with null strings.

Thanks,
Fred Herring
 
Ok, I tried this method and got an error. I am attempting to read into a
string variable a null sql value.

MyData(i).ChildIndexList = IIf(IsDBNull(dr.GetString(3)), "", dr.GetString(3))

An unhandled exception of type: sqlNullValueException occured in system
data.dll
Additional information:Data is null. This method cannot be called on null
values.

Suggestions?

Fred
 
Try this and it should work
MyData(i).ChildIndexList = IIf(IsDBNull(dr.Item(3)), "", dr.Item(3))

GetString expexts a string, and as of now can't deal with NULLs. At least
that's what I've been lead to believe. So, you would only want to use
GetString when you know there will be no NULL values.
 
Back
Top