如何使用OleDb删除数据库数据
这段代码运行到
thisAdapter.Update(thisDataSet, "cardno"); 时出现异常:“对于不返回任何键列信息的 SelectCommand,不支持 DeleteCommand 的动态 SQL 生成。”
代码如下:
private void buttonDele_Click(object sender, EventArgs e)
{
f_con = "FILE NAME=" + @"c:\cshis\cs2000.udl";
thisConnect = new OleDbConnection(f_con);
thisConnect.Open();
if (thisConnect.State == System.Data.ConnectionState.Open)
{
MessageBox.Show("it's OK");
}
thisAdapter = new OleDbDataAdapter(@"select * from cardno",thisConnect);
thisComm = new OleDbCommandBuilder(thisAdapter);
thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet,"cardno");
keys = new DataColumn[1];
keys[0]=thisDataSet.Tables["cardno"].Columns["rm_num"];
thisDataSet.Tables["cardno"].PrimaryKey = keys;
thisRow = thisDataSet.Tables["cardno"].Rows.Find("4444");
if (thisRow != null)
{
thisRow.Delete();
thisAdapter.Update(thisDataSet, "cardno");
MessageBox.Show("Delete is done");
}
所有变量都是声明过的,这只是代码的一部分。
有谁能告诉我是哪里写错了导致的这个异常么?