MySQL警告1264超出DateTime的范围值

时间:2022-02-14 16:39:01

I am trying to insert a datetime from a C# program textbox to a MySQL database. Every time I run the program in Visual Studio, I get the error:

我试图将一个日期时间从C#程序文本框插入MySQL数据库。每次我在Visual Studio中运行程序时,都会收到错误:

"Fatal error encountered during command execution."

“命令执行期间遇到致命错误。”

I tried running the query in MySQL to get a more specific response and received a warning 1264 out of range value error. The date appears to be in the proper format and I am converting to datetime before it is sent to MySQL. I have also checked my database column data type which is set to datetime. Why would I still be receiving this error?

我尝试在MySQL中运行查询以获得更具体的响应并收到警告1264超出范围值错误。日期似乎是正确的格式,我在转发到MySQL之前转换为datetime。我还检查了我的数据库列数据类型,该类型设置为datetime。为什么我仍然会收到此错误?

string sqlInsertBackup = "insert into backups (tape_num, bup_type, bup_date, bup_release, completed, date_created, date_modified) values (@tape_num, @backupType, @startDate, @releaseDate, 0, now(), now())";
MySqlCommand cmdInsertBackup = new MySqlCommand(sqlInsertBackup, idb.myconn);
cmdInsertBackup.Parameters.AddWithValue("@tapeNum", tapeNum);
cmdInsertBackup.Parameters.AddWithValue("@backupType", backupType);
cmdInsertBackup.Parameters.AddWithValue("@startDate", System.Convert.ToDateTime(startDate));
cmdInsertBackup.Parameters.AddWithValue("@releaseDate", System.Convert.ToDateTime(releaseDate));
cmdInsertBackup.ExecuteNonQuery();

1 个解决方案

#1


0  

Your first parameter is named @tape_num not @tapeNum, so it hasn't been given a value.

您的第一个参数名为@tape_num而不是@tapeNum,因此没有给出值。

#1


0  

Your first parameter is named @tape_num not @tapeNum, so it hasn't been given a value.

您的第一个参数名为@tape_num而不是@tapeNum,因此没有给出值。