总提示:索引超出范围。必须为非负值并小于集合大小。
极度郁闷中,困扰了一天了,做了4遍,结果还是一个样,紧急求救!!!!string strCon = "Data Source=(local);Database=baoming;Uid=sa;Pwd=admin";
SqlConnection sqlcon;
SqlCommand sqlcom;
protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from Stu_Info where userID='" + gvUser.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcon = new SqlConnection(strCon);
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}
public void bind()
{
string sqlstr = "select * from Stu_Info";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "Stu_Info");
gvUser.DataSource = myds;
gvUser.DataKeyNames = new string[] { "userID" };//主键
gvUser.DataBind();
sqlcon.Close();
}