无法将MySQL日期/时间值转换为VS2010中的System.DateTime

7

当我想从我的MySQL数据库中加载数据时,总是会出现以下错误:

无法将MySQL日期/时间值转换为System.DateTime

这是我的连接字符串:

<add name="gdmwebsiteEntities" 
     connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;database=gdmwebsite&quot;" 
     providerName="System.Data.EntityClient" />

我已经在连接字符串的末尾添加了"Convert Zero Datetime=True",但仍然没有改变。

    <add name="gdmwebsiteEntities" 
     connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;User Id=root;database=gdmwebsite&quot;
     Convert Zero Datetime=True
      Allow Zero Datetime=True"
     providerName="System.Data.EntityClient" />

有没有其他方法可以修复这个问题?
1个回答

22

在你的连接字符串中设置这两个配置项。

"Convert Zero Datetime=True"
"Allow Zero Datetime=True"

http://bugs.mysql.com/bug.php?id=26054

请参考连接选项中的手册,并将"Allow Zero Datetime"设置为true,如附图所示,则错误将消失。

同时也请查看:http://mdid.org/mdidwiki/index.php?title=Unable_to_convert_MySQL_date/time_value_to_System.DateTime_exception

要解决这个问题,请用NULL或有效的时间戳替换所有无效的时间戳,或者添加Allow Zero Datetime=true


我进行了更改,但是出现了配置错误。我做得对吗?(编辑了我的开始帖子) - nielsv
@niels123 请查看此链接 http://www.ironspeed.com/Designer/10.0.1/WebHelp/Part_VI/Unable_to_convert_MySQL_date_time_value_to_System_DateTime.htm 确保MySQL数据库中的日期列包含所有有效值或包含NULL。 - Soner Gönül

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接