错误提示: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); 之前也可以解决此问题
从而,不会保存失败了。