views:

19

answers:

1

Hi. I'm trying to extract a date field from a mysql db using .NET and MySQL .NET Connector.

Whithin the test everything works great except the date, I mean, I can get the varchar fields but the DATE field (called R_DATE) is impossible.

My SQL Query is:

SELECT * FROM TABLE

And, the way I'm trying to read it is:

DateTime date = reader.GetDateTime(COLUM_INDEX);

I just don't know what to do. I prove to explicity put the SELECT A, B, C... and didn't work, also tryed with SELECT A, DATE_FORMAT(B, '...) but also didn't.

Anything wrong?

Thanks for the help. Any tip will be very valuable.

EXCEPTION

Test method DocumentsManagementServiceTest.DataManagerTest.TestSearch threw exception: 
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
+1  A: 

You could test if the value is null before calling this method:

DateTime? date = null;
if (!reader.IsDBNull(COLUM_INDEX))
{
    date = reader.GetDateTime(COLUM_INDEX);
}
Darin Dimitrov
The thing is that the value Date is not null. I'm testing it against a fully loaded DB Table.
Sheldon
Actually this works!Why putting the ? after the DateTime makes it works?And... THANKS!!!
Sheldon