Why does compiling this code result in a syntax error?
I wrote the following code but i am getting th开发者_运维技巧e error as i mentioned can any one tell
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);
}
}
The syntax error comes from this statement:
dRow = local_ds.Tables[0].Select(strBnkArray.ToString().TrimEnd(','));
There is something wrong with the expression you are trying to use.
That expression is made up from this:
strBnkArray.ToString().TrimEnd(',')
Check what that is and you find the answer. Like this perhaps:
string mySelectStatement = strBnkArray.ToString().TrimEnd(',');
dRow = local_ds.Tables[0].Select(mySelectStatement);
WHy don't you use ArrayList
instead of String array. So that it will be easy to manipulate
Sample
if (chkItem.Checked)
{
chkItm = true;
chkcnt++;
strBankTypeID += ((Label)grRow.FindControl("lblBankType")).Text.ToString();
ArrayList lstArray=new ArrayList();
lstArray.Add(strBankTypeID);
}
Later
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);
}
精彩评论