无法将MySQL日期/时间值转换为System.DateTime [英] Unable to convert MySQL date/time value to System.DateTime
问题描述
这里的DeliveryClass CreatedDate为DateTime。当我运行应用程序时,我得到无法将MySQL日期/时间值转换为System.DateTime 。什么可能是问题?
格式的问题,实际上mysql有不同的格式(yyyy-mm-dd)对于日期/时间数据类型并解决这个问题,从这里使用.net的mysql连接器库
http://dev.mysql.com/downloads/connector/net/
它将给出名为MysqlDateTime的日期/时间的其他数据类型
,或者您可以使用DATE_FORMAT(日期,格式)
格式化sql语句中的日期/时间数据,您可以从这里获取更多详细信息
http://dev.mysql.com/doc/refman/5.1/ en / date-and-time-functions.html#function_date-format
但是我不建议这样做,因为你会放弃日期/时间数据类型(例如您无法比较),因为现在您将转换它要字符串,但我认为这将在报告
中有用
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?
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
这篇关于无法将MySQL日期/时间值转换为System.DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!