无法将MySQL日期/时间值转换为System.DateTime [英] Unable to convert MySQL date/time value to System.DateTime

查看:222
本文介绍了无法将MySQL日期/时间值转换为System.DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ibatis和C#。我从具有CreatedDate的select查询中获取结果作为其中一个字段。 Mysql中的CreatedDate数据类型为Date。我将选择查询的结果集分配给一个Ilist< DeliveryClass>。



这里的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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆