无法使用c#存储过程在MySQL中插入current_timestamp

时间:2014-06-03 07:00:57

标签: c# datetime mysql-workbench

示例代码段:

command.Parameters.Add(new MySqlParameter("@Created_Date", MySqlDbType.Datetime)).Value = DateTime.Now;

存储过程中的声明" Created_Date DATETIME"

error code: Input string was not in a correct format.

2 个答案:

答案 0 :(得分:0)

试试这个:

command.Parameters.Add(new MySqlParameter("@Created_Date", MySqlDbType.Timestamp)).Value = DateTime.Now;

答案 1 :(得分:-1)

MySqlDbType.Datetime枚举值已过时,请改用MySqlDbType.DateTime

Difference between DateTime and Timestamp in MySql

在您的情况下,只需使用command.Parameters.AddWithValue("@Created_Date", DateTime.Now)