Unable to convert MySQL date/time value to System.DateTime 解決方案
這個問題發生在MySQL數據里面有Date類型數據,在C#中查詢出來時候時間的類型不一致而導致!
網上看了一下,找到有兩種解決方案:
1、在連接字符串中加入“Allow Zero Datetime=True”;
con = new MySqlConnection("server=localhost;database=test;CharSet=gb2312;pooling=false;port=3306;UId=root;Pwd=pwd;Allow Zero Datetime=True");
這個是一勞永逸、未雨綢繆的辦法,加完就不用管了。
2、在用到有查詢數據的語句時候加上 CAST(date as char) 轉換一下:
eg(例如) : select CAST(字段名 as char) from tbl_test