views:

343

answers:

2

Hello

I am using ibatis and C#. i get a result from a select query that has CreatedDate as one of the field. The Datatype of CreatedDate in Mysql is Date. I assign the result set of the select query to a Ilist< DeliveryClass>.

Here the DeliveryClass CreatedDate as DateTime. When i run the application, i get Unable to convert MySQL date/time value to System.DateTime. What could be the problem?

A: 

The problem in the format, actually mysql have a different format (yyyy-mm-dd) for the date/time data type and to solve this problem use the mysql connector library for .net from here http://dev.mysql.com/downloads/connector/net/ it will give other data type for the date/time called MysqlDateTime

or you can format the date/time data in your sql statement using DATE_FORMAT(date,format) you can get more details from here http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

but i don't recommend this because you will loose the power of date/time data type (for example you can't compare) because now you will convert it to string but i think it will be useful in the reports

Amgad Fahmi
On updating the connector to the latest didn't solve my problem
Sri Kumar
the connector it self will not solve your problem it depends how you are retrieving your data ?? for example i used my generation doodads template i override the retrieving property for the datetime (reading the value from the datatable => convert it from mysqldatetime to .net datetime) how u retrieve your data ?
Amgad Fahmi
A: 

It could be outside the range of a DateTime object. I've seen that a couple of times. Try changing the sql to return the current date instead of your column and see if it comes through ok.

Dan