Checking for a null value

  • Thread starter Thread starter Sathyaish
  • Start date Start date
S

Sathyaish

How do you check if a value returned by a DataReader is null or not?
For instance, here's what I wish to check:


If Not Reader.HasRows Then
mPreviousArchivalDate = Nothing
Reader.Close()
Exit Sub
End If

Reader.Read()
If Reader("PreviousArchivalDate") = System.TypeCode.DBNull
Then 'This won't work, so I need a substitute
mPreviousArchivalDate = Nothing
Reader.Close()
Exit Sub
End If
mPreviousArchivalDate =
Convert.ToDateTime(Reader("PreviousArchivalDate"))


The above comparison with TypeCode.DBNull won't work. VB6 had an
IsNull() function in the VBA library. What does ADO.NET provide?
 
Back
Top