我正在尝试更新修改后的数据集,如下所示。我收到了错误。我该如何纠正这个问题?
未处理的类型' System.InvalidOperationException'发生在System.Data.dll中 其他信息:更新无法找到TableMapping ['表']或DataTable'表'。
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\ASWorx Products\\ASWorx200\\Database\\GemDatabase.mdb";
string strAccessSelect = "SELECT * FROM VariableTable";
// Create the dataset and add the Categories table to it:
DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = new OleDbConnection(strAccessConn);
OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "VariableTable");
DataRowCollection dra = myDataSet.Tables["VariableTable"].Rows;
foreach (DataRow dr in dra)
{
dr[1] = "SV";
break;
}
myDataAdapter.Update(myDataSet);
答案 0 :(得分:2)
您需要使用OleDbCommandBuilder对象 - 它会生成单表命令。
OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
OleDbCommandBuilder cmd=new OleDbCommandBuilder(myDataAdapter);
myDataAdapter.Fill(myDataSet, "VariableTable");
..
更新数据集结果,
myDataAdapter.Update(myDataSet,"VariableTable");