我有一个网格视图,当我单击第 2 页时,给出的错误在我的 sql 命令中突出显示:SqlCommand cmdShow = new SqlCommand("delete from Student where NRIC= '" + GridView1.DataKeys[0].Value + "'", conn);
并声明错误是:Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
这是我的代码:
protected void GridView1_RowDeleted(Object sender, GridViewCommandEventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=MCDU\\SQLEXPRESS;Initial Catalog=n;Integrated Security=True");
conn.Open();
SqlCommand cmdShow = new SqlCommand("delete from Student where NRIC= '" + GridView1.DataKeys[0].Value + "'", conn);
cmdShow.ExecuteNonQuery();
conn.Close();
Response.Redirect("studentParticulars.aspx");
}