我写了下面的代码,但是我收到了错误,因为我提到的任何人都可以告诉
protected void btnGenerate_Click(object sender, EventArgs e)
{
DataRow[] dRow;
DataTable dt = new DataTable();
foreach (GridViewRow grRow in grdACH.Rows)
{
CheckBox chkItem = (CheckBox)grRow.FindControl("checkRec");
if (chkItem.Checked)
{
chkItm = true;
chkcnt++;
strBankTypeID = ((Label)grRow.FindControl("lblBankType")).Text.ToString();
strBnkArray.Append(strBankTypeID);
strBnkArray.Append(",");
}
}
oEmpDeposits.getEmpDepositDetails(out local_ds, strFedTaxId, PayperiodNumber, PayrollYear, strPayFreqType);
for (int i = 0; i < local_ds.Tables[0].Rows.Count; i++)
{
string strTrim = strBnkArray.ToString().TrimEnd(',');
strTrim = "BankAccountTypeID='" + strTrim[i] + "'";
if (strTrim.Contains("BankAccountTypeID=',"))
{
strTrim = "BankAccountTypeID='" + strTrim[i] + "'";
}
dRow = local_ds.Tables[0].Select(strTrim);
}
}
答案 0 :(得分:2)
语法错误来自此声明:
dRow = local_ds.Tables[0].Select(strBnkArray.ToString().TrimEnd(','));
您尝试使用的表达式有问题。
该表达式由此构成:
strBnkArray.ToString().TrimEnd(',')
检查那是什么,然后找到答案。也许这样:
string mySelectStatement = strBnkArray.ToString().TrimEnd(',');
dRow = local_ds.Tables[0].Select(mySelectStatement);
答案 1 :(得分:0)
为什么不使用ArrayList
而不是String数组。这样操作起来很容易
样品
if (chkItem.Checked)
{
chkItm = true;
chkcnt++;
strBankTypeID += ((Label)grRow.FindControl("lblBankType")).Text.ToString();
ArrayList lstArray=new ArrayList();
lstArray.Add(strBankTypeID);
}
稍后
oEmpDeposits.getEmpDepositDetails(out local_ds, strFedTaxId, PayperiodNumber, PayrollYear, strPayFreqType);
for (int i = 0; i < lstArray.Count; i++)
{
//string strTrim = strBnkArray.ToString().TrimEnd(',');
strBankAccntType = "BankAccountTypeID='" + lstArray[i].ToString() + "'";
dRow = local_ds.Tables[0].Select(strBankAccntType);
}