C#插入Mysql时间字段报 Incorrect datetime value
kelvin 发布于 2020-12-19

在C#中插入Mysql报错,提示 Incorrect datetime value,原因是MySqlDbType用了MySqlDbType.VarChar,应该使用MySqlDbType.DateTime

不过也发现在本机win10系统上用MySqlDbType.VarChar没事,而在windows server2012服务器上才会报错。应该是时间转成字符串的时候,在win10上格式可以转换,而在windows server2012上字符串格式不对

 MySqlParameter param = new MySqlParameter("@CreateTime", MySqlDbType.DateTime);
param.Value = DateTime.Now;

kelvin
关注 私信
文章
92
关注
0
粉丝
0