DataGrid控件的问题??
protected void DataGrid1_DeleteCommand1(object source, DataGridCommandEventArgs e){
DataSet myDataSet =GetTable();
DataColumn[] keys = new DataColumn[1];
keys[0] =myDataSet.Tables[0].Columns[0];
myDataSet.Tables[0].PrimaryKey=keys;//以上是设立主键,以便以后用此作为判断的依据
try
{
OleDbConnection myConnection = new OleDbConnection(connStr);
myConnection.Open();
string insertStr = "delete from BOOK where id_no='" + DataGrid1.DataKeys[e.Item.ItemIndex] + "'";
OleDbCommand myCommand = new OleDbCommand(insertStr, myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
lblMsg.Text = "书号" + DataGrid1.DataKeys[e.Item.ItemIndex] + "这条记录已经被删除!!";
}
catch (Exception ee)
{
lblMsg.Text = ee.Message;
}
if (DataGrid1.CurrentPageIndex != 0 && DataGrid1.Items.Count == 1)
{
DataGrid1.CurrentPageIndex -= 1;
}
ShowAllBook();
}
红色的部分出现问题,异常处理给出的错误是:索引超出范围。必须为非负值并小于集合大小。参数名: index
不知道为什么,希望路过的朋友给予指点,谢谢!!!