enter code here
我被缺少参数“@comment”的错误所困扰。但是,我确信它不是空值,并且我已将所有必要的值传递到相应的参数中。
扫描代码几个小时后,我确定我的 SQL 命令没有丢失错误所述的“@comment”。
主程序将调用下面的方法并将相应的值传递给该方法。根据这些属性值,它将调用要使用的 8 条 sql 命令中的 1 条。
在这种情况下该怎么做有什么建议吗?谢谢。
在将属性值传递给方法之前,我使用以下代码验证了我的属性值。
//-------Checklist 5-------
itemID = "dnaIN"; type = "in";
if (string.IsNullOrEmpty(lblD5.Text) == false)
{ objR.CheckBy = lblD5.Text; }
else if (string.IsNullOrEmpty(lblD5.Text) == true)
{ objR.CheckBy = "0"; }
if (string.IsNullOrEmpty(lblV5.Text) == false)
{ objR.VerifiedBy = lblV5.Text; }
else if (string.IsNullOrEmpty(lblV5.Text) == true)
{ objR.VerifiedBy = "0"; }
if (string.IsNullOrEmpty(lblsbC.Text) == false) // check if user type comments
{ objR.Comment = lblsbC.Text; }
else
{ objR.Comment = "0"; }
update = objR.update(formID, itemID, type);
//------------传递给下面的代码----------
string strConn = Convert.ToString(ConfigurationManager.ConnectionStrings["InternshipConnectionString"]);
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd1 = new SqlCommand();
//program pass in 0 as null for checkby & verifiedby
if (_CheckBy != "0" && _VerifiedBy != "0" && type == "in") // user enter everything, system in
{
cmd1 = new SqlCommand("UPDATE SystemIn SET CheckBy =@checkBy, VerifiedBy =@verifiedBy WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (_CheckBy != "0" && _VerifiedBy == "0" && type == "in") // user enter checkBy only,
{
cmd1 = new SqlCommand("UPDATE SystemIn SET CheckBy =@checkBy, VerifiedBy = NULL WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (type == "in")
{
cmd1 = new SqlCommand("UPDATE SystemIn SET CheckBy = NULL, VerifiedBy =NULL WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (_CheckBy != "0" && _VerifiedBy != "0" && _Comment != "0" && type == "out")
{
cmd1 = new SqlCommand("UPDATE SystemOut SET CheckBy =@checkBy, VerifiedBy =@verifiedBy, Comment=@comment WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (_CheckBy != "0" && _VerifiedBy == "0" && _Comment == "0" && type == "out")
{
cmd1 = new SqlCommand("UPDATE SystemOut SET CheckBy =@checkBy, VerifiedBy = NULL, Comment=NULL WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (_CheckBy != "0" && _Comment != "0" && _VerifiedBy == "0" && type == "out")
{
cmd1 = new SqlCommand("UPDATE SystemOut SET CheckBy =@checkBy, VerifiedBy=NULL, Comment=@comment WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (_CheckBy != "0" && _Comment == "0" && _VerifiedBy != "0" && type == "out")
{
cmd1 = new SqlCommand("UPDATE SystemOut SET CheckBy =@checkBy, VerifiedBy =@verifiedBy, Comment=NULL WHERE FormID =@formID AND ItemID =@itemID", conn);
}
else if (type == "out")
{
cmd1 = new SqlCommand("UPDATE SystemOUT SET CheckBy = NULL, VerifiedBy = NULL, Comment=NULL WHERE FormID =@formID AND ItemID =@itemID", conn);
}
cmd1.Parameters.AddWithValue("@formID", formID);
cmd1.Parameters.AddWithValue("@itemID", itemID);
if (_CheckBy != "0")
{ cmd1.Parameters.AddWithValue("@checkBy", _CheckBy); }
if (_VerifiedBy != "0")
{ cmd1.Parameters.AddWithValue("@verifiedBy", _VerifiedBy); }
if (_Comment != "0")
{ cmd1.Parameters.AddWithValue("@comment", _Comment); }