我通过这个C#代码在gridview中获取数据。 但是如果我根据我的代码传递超过1个值作为资产编号,它会给我回复我的预定义错误。 如果我一次只通过一个资产编号,它绝对精确。 请帮助。
private void UpdateAssetNumber (string requestId)
{
clsDatabase objDb = new clsDatabase();
clsUtility objUtil = new clsUtility();
SendEmail objMail = new SendEmail();
SqlTransaction objTrans;
string TableName = "Assets_Requisition_Detail_Controller";
string FieldsName = string.Empty;
string FieldsValue = string.Empty;
string todayDate = objUtil.fncGetDate();
bool flg = false;
try
{
objDb.fncOpenConnection();
objTrans = objDb.cnnConnection.BeginTransaction();
FieldsName = "Asset_No$";
foreach (GridViewRow row in grdEntry.Rows)
{
Label lblDetailId = row.FindControl("lblDetailId") as Label;
TextBox txtAssetNo = row.FindControl("txtAssetNo") as TextBox;
FieldsValue = "'" + txtAssetNo.Text + "'$'";
flg = objDb.fncModifyRecord(TableName, FieldsName, FieldsValue, "Request_Id= " + requestId + " AND IsActive = 'TRUE' AND Detail_Id = " + lblDetailId.Text, ref objDb.cnnConnection, ref objTrans);
if (!flg)
{
break;
}
}
if (flg)
{
flg = UpdateRquestStatus(lblPk.Text, ref objDb.cnnConnection, ref objTrans);
}
if (flg)
{
objTrans.Commit();
SearchRequest();
pnlNew.Visible = false;
pnlSearch.Visible = true;
lblMsg.Text = objUtil.fncGetErrorDesc(1);
objMail.SendCodeOpenedEmail("ASSET", Convert.ToInt32(lblPk.Text));
}
else
{
objTrans.Rollback();
lblMsg.Text = objUtil.fncGetErrorDesc(-1);
}
pnlMsg.Visible = true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
objDb.fncCloseConnection(objDb.cnnConnection);
objTrans = null;
}
}
答案 0 :(得分:1)
您可以从调用者创建它,而无需更改此方法或使用另一个将列表作为参数的UpdateAssetNumber方法。类似的东西:
private void UpdateAssetNumber (List<string> requestIds)
{
foreach(var requestId in requestIds)
{
UpdateAssetNumber(requestId)
}
}
答案 1 :(得分:0)
这是因为您只识别了一个输入参数
private void UpdateAssetNumber (string requestId) {
尝试
private void UpdateAssetNumber(params string[] list) {