oledbDataReader - how to read Date value?

J

James

....
rdr = cmd.ExecuteReader()
Do While rdr.Read()
For i = 0 To rdr.FieldCount - 1
If Not rdr.IsDBNull(i) Then
Console.WriteLine(rdr.GetString(i))
End If
Next
Loop

The data rdr is reading consists of text, dates, and
numbers. It is having a casting problem on the date
values. How can I read a date value with an
oledbDataReader?

Thanks
 
A

Arne Janning

Hi James!

...
rdr = cmd.ExecuteReader()
Do While rdr.Read()
For i = 0 To rdr.FieldCount - 1
If Not rdr.IsDBNull(i) Then
Console.WriteLine(rdr.GetString(i))
End If
Next
Loop

The data rdr is reading consists of text, dates, and
numbers. It is having a casting problem on the date
values. How can I read a date value with an
oledbDataReader?

Did you try rdr.GetDateTime() or
DateTime.Parse(rdr.GetString()) ?

Cheers

Arne Janning
 
J

James

No. I haven't. Of course, that would be a property that I
missed, rdr.GetDateTime. My head was spinning around too
fast this afternoon. And, no I did not try
DateTime.Parse. But I will try each of this tommorrow.

Thanks for the help.
 

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