使用datagrid更新信息出错
我用datagrid修改信息使用了以下代码,可是点击提交之后,出现错误。代码为:
this.oleDbDataAdapter1.SelectCommand.CommandText = "select * from admin ";
this.oleDbDataAdapter1.SelectCommand.Connection = this.oleDbConnection2;
System.Data.OleDb.OleDbCommandBuilder mybuilder = new System.Data.OleDb.OleDbCommandBuilder(this.oleDbDataAdapter1);
this.oleDbDataAdapter1.UpdateCommand = mybuilder.GetUpdateCommand();
this.oleDbDataAdapter1.UpdateCommand.Connection = this.oleDbConnection2;
this.oleDbDataAdapter1.DeleteCommand = mybuilder.GetDeleteCommand();
this.oleDbDataAdapter1.DeleteCommand.Connection = this.oleDbConnection2;
this.oleDbDataAdapter1.InsertCommand = mybuilder.GetInsertCommand();
this.oleDbDataAdapter1.InsertCommand = mybuilder.GetInsertCommand();
try
{
DialogResult result1;
result1=MessageBox.Show("您确定要修改此项内容吗?","系统提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(result1==DialogResult.OK)
{
this.oleDbDataAdapter1.Update(this.ds1,"admin");
MessageBox.Show("修改成功","系统提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
}
return;
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
错误提示为:update 无法找到Tablemapping['admin']或datatable"admin"
其中“admin”为所要操作的表