The exception is thrown with the last possibility (subtract_QtyFromStock_Ex < 0). "Procedure or function DeleteFromtb_QtyEx has too many arguments specified." even the stated procedure isn't to be called inside the loop in this possibility.
I checked the number of parameters I don't use a global sqlcommand I tested the function separately and it's doing well
The stored procedure with the problem
ALTER proc [dbo].[DeleteFromtb_QtyEx]
@autoCodeIdentifier int
As
Delete from tb_Quantity_Expire
where tb_Quantity_Expire.item_auto_code=@autoCodeIdentifier
The code at DataAccessLayer
public void ExecuteCommand(string stored_procedure, SqlParameter[] param)
{
SqlCommand cmd = new SqlCommand(stored_procedure, con);
cmd.CommandType = CommandType.StoredProcedure;
if(param != null)
{
cmd.Parameters.AddRange(param);
}
cmd.ExecuteNonQuery();
}
Code at the class
public void DeleteFromtb_QtyEx(int autoCodeIdentifier)
{
Cls_DataAccessLayer DAL = new Cls_DataAccessLayer();
DAL.OpenCon();
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@autoCodeIdentifier", SqlDbType.Int);
param[0].Value = autoCodeIdentifier;
DAL.ExecuteCommand("DeleteFromtb_QtyEx", param);
DAL.CloseCon();
}
Code on btn_click
private void btnTender_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
decimal qty_entered =
Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value);
decimal stk =
Convert.ToDecimal(dataGridView1.Rows[i].Cells[5].Value);
decimal subtract = stk - qty_entered;
if (subtract < 0)
{
Cls.DeleteFromtb_QtyEx(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value));
Cls.InsertTotb_QtyEx(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value), subtract);
}else if(subtract==0)
{
Cls.DeleteFromtb_QtyEx(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value));
Cls.InsertTotb_QtyEx(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value), subtract);
}else if (subtract > 0)
{
DataTable dt_QtyEx = new DataTable();
dt_QtyEx = Cls.SelectFromtb_QtyEx(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value));
decimal subtract_QtyFromStock_Ex = 0;
//decimal qty = Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value);
for (int x = 0; x < dt_QtyEx.Rows.Count; x++)
{
if (x == 0)
{
subtract_QtyFromStock_Ex = Convert.ToDecimal(dt_QtyEx.Rows[x][2]) - qty_entered;
}
else
{
subtract_QtyFromStock_Ex = Convert.ToDecimal(dt_QtyEx.Rows[x][2]) - (0 - subtract_QtyFromStock_Ex);
}
if (subtract_QtyFromStock_Ex > 0)
{
Cls.Updatetb_QtyEx(Convert.ToInt32(dt_QtyEx.Rows[x][0]), Convert.ToDateTime(dt_QtyEx.Rows[x][1]), subtract_QtyFromStock_Ex);
break;
}
else if (subtract_QtyFromStock_Ex == 0)
{
Cls.DeleteFromtb_QtyEx_Expire(Convert.ToInt32(dt_QtyEx.Rows[x][0]), Convert.ToDateTime(dt_QtyEx.Rows[x][1]));
break;
}
else if (subtract_QtyFromStock_Ex < 0)
{
Cls.DeleteFromtb_QtyEx_Expire(Convert.ToInt32(dt_QtyEx.Rows[x][0]), Convert.ToDateTime(dt_QtyEx.Rows[x][1]));
}
}
}
}
谢谢大家.....抛出异常是因为我在另一个存储过程“DeleteFromtb_QtyEx_Expire”的函数中调用存储过程“DeleteFromtb_QtyEx”犯了可怕的错误
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.