invalid cast prob with oleDBdataReader

  • Thread starter Thread starter James
  • Start date Start date
J

James

....
Dim rdr As OleDbDataReader = cmd.ExecuteReader
If rdr.GetString(1).ToString.Length > 0 Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

The field is in an MS Access table that rdr is reading and
is a text field. I am getting an invalid cast error when
the field is null/empty.

I have tried If Not IsDBNull(rdr.GetString(1).ToString)...

still same problem. How can I trap if the field is null?

Thanks
 
If Not rdr.IsDBNull(1) Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

hope that helps..
Imran.
 
Yes. Thank you. That did the trick!

-----Original Message-----
If Not rdr.IsDBNull(1) Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

hope that helps..
Imran.




.
 
Back
Top