日期:2014-05-17  浏览次数:20454 次

索引超值和表达式中数据类型不匹配的问题.
this.DataGrid1.DataKeyField = "ID"; //这行是在函数里写的。取得id
.
.
.
.
.
 string id = this.DataGrid1.DataKeyField[e.Item.ItemIndex].ToString(); //去第一行不提示错误,第二行以上显示索引超值,去不到值。
  OleDbConnection con = new OleDbConnection(db.conntion());

  OleDbCommand cmd = new OleDbCommand("delete from book where ID = '"+ id +"'" ,con);
  con.Open();
  cmd.ExecuteNonQuery();//这行提示数据类型不匹配。
  con.Close();
  this.datagridsorce();

------解决方案--------------------
.DataKeyField[e.Item.ItemIndex],这个超出范围了,越界了,ItemINdex是多少,DataKeyField没有那么多项