并发冲突:- UpdateCommand 影响了预期的 1 条记录中的 0 条
Concurrency violation:- the UpdateCommand affected 0 of the expected 1 records
我们正在使用 windows 表格。在表单中,我们有 gridview,我们在其中执行插入新行并一起更新现有行。下面的过程是代码,
OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
OracleCommandBuilder oraCmdBuilder = new OracleCommandBuilder(adapter);
OracleDataAdapter adap = new OracleDataAdapter();
adap.SelectCommand = new OracleCommand(sql, conn);
adap.InsertCommand = oraCmdBuilder.GetInsertCommand();
adap.InsertCommand.Connection = conn;
adap.UpdateCommand = oraCmdBuilder.GetUpdateCommand();
adap.UpdateCommand.Connection = conn;
adap.DeleteCommand = oraCmdBuilder.GetDeleteCommand();
adap.DeleteCommand.Connection = conn;
adap.UpdateBatchSize = 100;
int i = adap.Update(deltaTable);
其中 InsertCommand
工作正常并在 adap.Update(deltaTable);
中抛出异常,如下所示,
Concurrency violation: the UpdateCommand affected 0 of the expected 1
records. we tried to add acceptchanges before update method, but that
change was affecting delete . The row was not deleting.
欢迎提出任何建议。
提前致谢。
此致
我遇到了这个问题,原因如下
1) 在您的 update
查询中,您在更新之前使用原始数据控制了数据。要解决从查询中删除此条件。如果您删除条件,则它变为 last modified win
。条件有 @original
前缀。像
这样的查询
WHERE CustomerID = @Original_CustomerID OR @Original_CustomerID IS NULL AND customer ID IS NULL
2) 在代码的 Update
之前 Row.AcceptChanges()
我们正在使用 windows 表格。在表单中,我们有 gridview,我们在其中执行插入新行并一起更新现有行。下面的过程是代码,
OracleDataAdapter adapter = new OracleDataAdapter(sql, conn);
OracleCommandBuilder oraCmdBuilder = new OracleCommandBuilder(adapter);
OracleDataAdapter adap = new OracleDataAdapter();
adap.SelectCommand = new OracleCommand(sql, conn);
adap.InsertCommand = oraCmdBuilder.GetInsertCommand();
adap.InsertCommand.Connection = conn;
adap.UpdateCommand = oraCmdBuilder.GetUpdateCommand();
adap.UpdateCommand.Connection = conn;
adap.DeleteCommand = oraCmdBuilder.GetDeleteCommand();
adap.DeleteCommand.Connection = conn;
adap.UpdateBatchSize = 100;
int i = adap.Update(deltaTable);
其中 InsertCommand
工作正常并在 adap.Update(deltaTable);
中抛出异常,如下所示,
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. we tried to add acceptchanges before update method, but that change was affecting delete . The row was not deleting.
欢迎提出任何建议。
提前致谢。
此致
我遇到了这个问题,原因如下
1) 在您的 update
查询中,您在更新之前使用原始数据控制了数据。要解决从查询中删除此条件。如果您删除条件,则它变为 last modified win
。条件有 @original
前缀。像
WHERE CustomerID = @Original_CustomerID OR @Original_CustomerID IS NULL AND customer ID IS NULL
2) 在代码的 Update
之前 Row.AcceptChanges()