错误提示:Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
             (UpdateCommand影响了预期1条记录中的0条)

原因: 对具有自增列的表进行新增并多次保存,由于第一次保存(插入)后没有获得到自增列的值,再次保存(更新)时失败。

解决方法(1),在获取数据时增加FillSchema()操作:

adapter.FillSchema(ds, SchemaType.Mapped);//new added

adapter.Fill(ds);

这样,在adapter.Update(ds); 时就可以自动得到自增列的值;

解决方法(2),

adapter.FillSchema(ds, SchemaType.Mapped);//new added

将此段话添加到 adapter.Update(ds); 之前也可以解决此问题

从而,不会保存失败了。

相关文章:

  • 2021-06-17
  • 2022-12-23
  • 2021-04-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
猜你喜欢
  • 2021-08-10
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2021-10-29
  • 2021-11-21
相关资源
相似解决方案