MySQL数据库中出现的unable to convert MySQL date/time value to System.DateTime及其FUNCTION MAX does not exist.

一、问题:unable to convert MySQL date/time value to System.DateTime

分析:这个原因是因为:表里的日期字段存在00-00-00 00:00:00这样的时间,所以在进行比较的时候就会出现这样的错误。

解决办法:

①在MySQL数据库的连接字符串后面添加“allow zero datetime=true:”如下所示:

string ConString="Server=127.0.0.1;database=testmysql;uid=root;password=123456;CharSet=gb2312;allow zero datetime=true;"

②将表中的时间字段的缺省值设置为null,而不是0000-00-00/0000-00-00 00:00:00的情况; 

③将表中的时间字段的类型设置为字符串类型比如varchar(30)

 

二、问题:FUNCTION MAX does not exist. Check the ‘Function Name Parsing and Resolution’ section in the Reference Manual” or “1305: FUNCTION MAX does not exist”.

解决办法:

①将SUM或者MAX方法后面的空格全部去掉,如下所示:

报错的sql语句为:SELECT MAX  (  id   )   as something FROM Example

修改后的正确语句为:SELECT MAX (id) as something FROM Example

 

注意:本内容参考:https://www.cnblogs.com/aeron/archive/2012/08/30/2663908.html

                                https://blog.csdn.net/hww9011/article/details/23864735

                                http://www.rufunka.com/blog/2011/03/24/mysql-1305-or-1630-error-function-does-not-exist/

                                https://blog.csdn.net/Oliverdada/article/details/82875639

 

 

 

 

 

 

 

你可能感兴趣的:(DataBase)