invalid cast prob with oleDBdataReader

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
 
I

Imran Koradia

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

hope that helps..
Imran.
 
J

James

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.




.
 

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

Top