关于C#连接MySQL数据转换问题,异常Unable to convert MySQL date/time value to System.DateTime, HResult=0x8013150

C#读取MySql时,如果存在字段类型为date/datetime时的可能会出现以下问题
“Unable to convert MySQL date/time value to System.DateTime”

原因:可能是该字段(date/datetime)的值默认值为:0000-00-00/0000-00-00 00:00:00,这样的数据读出来转换成System.DateTime时就会有问题;

解决办法:
1、将该字段的缺省值设置为null,而不是0000-00-00/0000-00-00 00:00:00的情况;
2、在链接MySQL的字符串中添加: Allow Zero Datetime=True;

3、将该字段设置成字符串类型;

小编建议使用第二种

答案来自google:点击打开链接

猜你喜欢

转载自blog.csdn.net/qq_41165844/article/details/80373889