过程或函数“批准”需要参数“@ApproveID”,但未提供
本文关键字:@ApproveID 函数 批准 过程 参数 | 更新日期: 2023-09-27 18:33:23
>我尝试通过以下代码批准文档
if (e.CommandName == "_Approve")
{
//using (SqlConnection con = DataAccess.GetConnected())
using (SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["mydms"]
.ConnectionString))
{
try
{
con.Open();
int rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = (GridViewRow)
((Control)e.CommandSource).NamingContainer;
Button Prove_Button = (Button)row.FindControl("BtnApprove");
SqlCommand cmd = new SqlCommand("approve", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserID", UserID));
cmd.Parameters.Add(new SqlParameter("@DocID", DocID));
cmd.Parameters.Add(new SqlParameter("@ApproveID", ApproveID));
int result = cmd.ExecuteNonQuery();
if (result != 0)
{
GrdFileApprove.DataBind();
}
}
catch
{
apfi.Text = "Not Approve";
}
finally
{
con.Close();
}
}
}
else if (e.CommandName == "_Reject")
{
using (SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings
["mydms"].ConnectionString))
{
try
{
con.Open();
int rowindex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = (GridViewRow)
((Control)e.CommandSource).NamingContainer;
LinkButton Prove_Button = (LinkButton)row.FindControl("Button1");
SqlCommand cmd = new SqlCommand("sprejectapprove", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserID",UserID));
cmd.Parameters.Add(new SqlParameter("@DocID", DocID));
cmd.Parameters.Add(new SqlParameter("@ApproveID", ApproveID));
int result = cmd.ExecuteNonQuery();
if (result != 0)
{
GrdFileApprove.DataBind();
}
}
catch
{
apfi.Text = "Rejct";
}
finally
{
con.Close();
}
}
}
和批准商店程序是
@UserID int,
@DocID int,
@ApproveID int
as
insert into Approval(UserID,DocID,ApproveID)
VALUES(@UserID,@DocID,@ApproveID)
在SQL中,有批准类型表,其中有批准和批准类型和批准类型有 3 种类型 1 是批准 2 拒绝,3 是待处理
在批准表中有用户ID,文档,批准ID
因此,当我调试代码时,它在批准部分捕获中给我错误
过程或函数"批准"需要参数"@ApproveID",但未提供。 请提供任何帮助 谢谢
我猜ApproveID
的值为 null
.由于 ADO.NET 有些疯狂,null
参数不会发送。你需要:
cmd.Parameters.Add(new SqlParameter("@ApproveID", (object)ApproveID ?? DBNull.Value));
或更简单:
cmd.Parameters.Add("ApproveID", (object)ApproveID ?? DBNull.Value);
甚至更容易的是,使用"dapper"更容易正确处理它:
con.Execute("approve", new {
UserID, DocID, ApproveID
}, commandType: CommandType.StoredProcedure);