我在c#中有一个存储过程,我将值添加到然后执行:
string query = "INSERT INTO equipment_parameter (parameter_group_name, version, operation_name, parameter_name, parameter_value, default, owner, date_created) VALUES(@parameter_group_name, @version, @operation_name, @parameter_name, @parameter_value, @default, @owner, @date_created)"; //stored procedure
//open connection
if (mySQLA.OpenConnection() == true)
{
//create command
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = mySQLA.getConnection();
cmd.CommandText = query;
cmd.Prepare();
//string
cmd.Parameters.AddWithValue("@parameter_group_name", eParam.ParameterGroupName);
//int
cmd.Parameters.AddWithValue("@version", eParam.Version);
//string
cmd.Parameters.AddWithValue("@operation_name", eParam.OperationName);
//string
cmd.Parameters.AddWithValue("@parameter_name", eParam.ParameterName);
//double
cmd.Parameters.AddWithValue("@parameter_value", eParam.ParameterValue);
//bool
cmd.Parameters.AddWithValue("@default", eParam.Default);
//string
cmd.Parameters.AddWithValue("@owner", eParam.Owner);
//DateTime
cmd.Parameters.AddWithValue("@date_created", eParam.DateCreated);
//Execute command
try
{
rowsCreated = cmd.ExecuteNonQuery(); //returns number of rows affected
}
catch (MySqlException es)
{
MessageBox.Show(es.Message, "Equipment Parameter Query Error: ");
}
当我运行这个程序时,它会尝试插入,然后我会捕获说明的异常:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default, owner, date_created) VALUES('object1', 1, 'Op1', 'object1', 10.01, 1, '' at line 1
我正在尝试执行的查询将读取如下内容:
INSERT INTO equipment_parameter (parameter_group_name, version, operation_name, parameter_name, parameter_value, default, owner, date_created) VALUES('object', 1, 'Op1', 'object1', 10.01, false, 'James', '2013-10-30 09:00:54')
我已经将'max_allowed_packet'增加到500M并重新启动了服务器,尽管这没有效果。我可以增加其他缓冲区大小选项或可能是我的问题吗?
答案 0 :(得分:0)
用我的脑袋沸腾后,我才意识到default
是一个保守的词。因此,它必须被反击:
[...] parameter_value, `default`, owner, date_created) [...]