并发冲突:-UpdateCommand影响了预期的1条记录中的0条



我们使用的是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);中抛出异常,如下所示,

并发冲突:UpdateCommand影响了预期1中的0记录。我们试图在更新方法之前添加acceptchanges,但是更改正在影响删除。该行未删除。

欢迎提出任何建议。

提前谢谢。

问候

我遇到了这个问题以及的以下原因

1) 在您的update查询中,您在更新之前已使用原始数据控制了数据。若要解决此问题,请从查询中删除此条件。若移除条件,那个么它将转到last modified win。条件具有@original前缀。类似的查询

WHERE CustomerID = @Original_CustomerID OR @Original_CustomerID IS NULL AND  customer ID IS NULL

2) 在代码中的Update之前,任何有Row.AcceptChanges()的地方

最新更新