Question : Converting an Access Date/Time column's value to a DateTime object

My program is throginw an exception on this line:

DateTime time = reader.GetDateTime(date_time_sentIndex);

But I do not understand why? It's a C# program trying to read that value from an Access database.

Here's the exception:
Specified cast is not valid. line:606 stracktrace:   at System.Data.OleDb.ColumnBinding.ValueDateTime()

I have verified the column number is valid, and do not know what I'm doing wrong.

Could someone please help?

newbieweb

Answer : Converting an Access Date/Time column's value to a DateTime object

Try

DateTime time = Convert.ToDateTime(reader.GetDateTime(date_time_sentIndex));

HTH
Ashok
Random Solutions  
 
programming4us programming4us