私はグリッド ビューを持っています。ページ 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");
}