郁闷
private void DataGrid1_ItemDataBound_1(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(!i)
{
e.Item.Cells[3].Text = "测试";
}
else
{
string CommandText = "select count(*) as count from zrbhdetail where parent=" + e.Item.Cells[0].Text;
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["conn"]);
SqlCommand Command = new SqlCommand(CommandText, myConnection);
myConnection.Open();
int total = (int)Command.ExecuteScalar();
myConnection.Close();
// return total.ToString();
e.Item.Cells[3].Text = total.ToString();
// e.Item.Cells[3].Text = GetCount(e.Item.Cells[0].Text);
}
i=true;
}
错误:
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '&' 附近有语法错误。
源错误:
行 87: SqlCommand Command = new SqlCommand(CommandText, myConnection);
行 88: myConnection.Open();
行 89: int total = (int)Command.ExecuteScalar();
行 90: myConnection.Close();
行 91: // return total.ToString();