連接MySQL時出現錯誤"unable to convert MySQL date/time value to System.DateTime"

  • 746
  • 0
  • C#
  • 2021-08-17

MySQL

unable to convert MySQL date/time value to System.DateTime

C#

使用C#

連接MySQL時出現錯誤"unable to convert MySQL date/time value to System.DateTime"時,只要改連線字串加入allow zero datetime=true

或 Convert Zero Datetime=True;
        private void button1_Click(object sender, EventArgs e)
        {
            String connetStr = "server=172.30.200.xxx;user=root;database=xxxx;port=3306;password=xxxx;allow zero datetime=true";//database是資料庫名字

            MySqlConnection conn = new MySqlConnection(connetStr);
            try
            {
                conn.Open();//開啟通道,建立連線,可能出現異常,使用try catch語句
                //Response.Write("已經建立連線");
                MessageBox.Show("已經建立連線");

                //在這裡使用程式碼對資料庫進行增刪查改
            }
            catch (MySqlException ex)
            {
                //Response.Write(ex.Message);
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }