CREATE PROCEDURE sp_ProductAdjustment (IN `_product_code` varchar(35), IN `_adjusted_qty` int, IN `_stock_in_out` char(3), IN `_status` varchar(10)) BEGIN ***some codes here*** END
public bool ProductAdjustment(string prodcode, int qty,string in_out,string status) { conn = Database.getConnection(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "sp_ProductAdjustment"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("_product_code", MySqlDbType.VarChar).Value = prodcode; cmd.Parameters["_product_code"].Direction = ParameterDirection.Input; cmd.Parameters.Add("_adjusted_qty", MySqlDbType.Int32).Value = qty; cmd.Parameters["_adjusted_qty"].Direction = ParameterDirection.Input; cmd.Parameters.Add("_stock_in_out", MySqlDbType.VarChar).Value = in_out; cmd.Parameters["_stock_in_out"].Direction = ParameterDirection.Input; cmd.Parameters.Add("_status", MySqlDbType.VarChar).Value = status; cmd.Parameters["_status"].Direction = ParameterDirection.Input; if (cmd.ExecuteNonQuery() == 1) **error on this line** { return true; } else { return false; } }catch(MySqlException ex) { MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message); return false; } finally { conn.Close(); } }
string in_out = radioButton1.Checked ? "IN" : "OUT"; if (prod.ProductAdjustment(txtproductCode.Text, Convert.ToInt32(numericUpDown_adjust.Value.ToString()), in_out, comboBox_reasons.Text)) { MessageBox.Show("Product Adjusted"); }
我只是在尝试任何事情,直到我得到调用存储过程的正确解决方案。这是我的建议:
cmd.Connection = conn; cmd.CommandText = "call sp_ProductAdjustment(@product_code, @adjusted_qty, @stock_in_out, @status)"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@product_code", MySqlDbType.VarChar).Value = prodcode; cmd.Parameters["@product_code"].Direction = ParameterDirection.Input; cmd.Parameters.Add("@adjusted_qty", MySqlDbType.Int32).Value = qty; cmd.Parameters["@adjusted_qty"].Direction = ParameterDirection.Input; cmd.Parameters.Add("@stock_in_out", MySqlDbType.VarChar).Value = in_out; cmd.Parameters["@stock_in_out"].Direction = ParameterDirection.Input; cmd.Parameters.Add("@status", MySqlDbType.VarChar).Value = status; cmd.Parameters["@status"].Direction = ParameterDirection.Input;
CommandType
CommandType.StoredProcedure
CommandType.Text
cmd.CommandText = "sp_ProductAdjustment";
cmd.CommandText = "call sp_ProductAdjustment(@product_code, @adjusted_qty, @stock_in_out, @status)";
sp_ProductAdjustment(parameters here)