运行以下代码时出现此错误
不支持UpdateCommand的动态SQL生成 一个不返回任何键列信息的SelectCommand。
尝试做很多事情没有任何效果。以下是代码
string queryUp = "SELECT Node_A_ObjectID,Node_Z_ObjectID FROM NDDILinks";
string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\TiptonDB.mdb";
DataSet dtup = new DataSet();
using (OleDbConnection myConnection = new OleDbConnection())
{
myConnection.ConnectionString = myConnectionString;
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = myConnection;
myConnection.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(queryUp, myConnection);
adp.FillSchema(dtup, SchemaType.Source, "NDDILinks");
adp.Fill(dtup, "NDDILinks");
dtup.Tables[0].Rows[1][0] = 2350;
adp.AcceptChangesDuringUpdate = true;
OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(adp);
cmd.Parameters.Add("@Node_A_ObjectID", OleDbType.Integer, sizeof(int), "Node_A_ObjectID");
int a1 = adp.Update(dtup, "NDDILinks");
dtup.AcceptChanges();
答案 0 :(得分:2)
我不是只选择主键2个值 Node_A_ObjectID,Node_Z_ObjectID。我还需要选择主键吗?
根据您对帖子的评论。您必须为UPDATE选择主键才能使用数据集,或者您可以指定自己的UPDATE或INSERT查询。您可能还会在MSDN上看到this discussion