一道关于GridView中RowDeleting的问题
代码如下:
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string sqlstrUD = "update xsxx set ";
sqlstrUD +="xm= '" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[2].Controls[0]).Text + "',";
sqlstrUD += "xb='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[3].Controls[0]).Text + "',";
sqlstrUD +="pwd='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[4].Controls[0]).Text +"',";
sqlstrUD +="bjmc='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[5].Controls[0]).Text +"',";
sqlstrUD +="zymc='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[6].Controls[0]).Text +"',";
sqlstrUD +="xxzydh='" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[7].Controls[0]).Text +"'";
sqlstrUD += " where xh= '" + ((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text + "'";
bool test= da.ExceSQL(sqlstrUD); //调用方法执行SQL语句
if(test==true)
{
Response.Write("更新成功");
}
else
{
Response.Write("更新失败");
}
GridView2.EditIndex = -1;
dlBind();
}
以上对数据库的更新完全可以,而下面的删除代码出了问题
protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstrDT="delete from xsxx where xh=";
sqlstrDT += " '" +((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text+"'";
bool test = da.ExceSQL(sqlstrDT);
if (test == true)
{
Response.Write("删除操作成功!");
GridView2.EditIndex = -1;
dlBind();
}
else
{
Response.Write("删除失败!");
}
}
错误显示行“sqlstrDT += " '" +((TextBox)GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text+"'";”
错误信息:指定的参数已超出有效值的范围。参数名: index
其中 数据库中xh的类型为char 要删除的值中 xh='012006026531'
希望网友抽空帮忙解决一下, 使其能正常删除,谢谢啦!!