1

我在 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_pa​​cket' 增加到 500M 并重新启动了服务器,尽管这没有任何效果。我可以增加其他缓冲区大小选项吗?或者我的问题是什么?

4

1 回答 1

0

在用这个沸腾我的头之后,我才意识到这default是一个保留字。因此,它必须被反引号:

[...] parameter_value, `default`, owner, date_created) [...]
于 2013-10-30T17:26:37.263 回答