datagridview主键与服务器主键dbConcurrencyException不同 [英] datagridview primary key differs from servers primary key dbConcurrencyexception
本文介绍了datagridview主键与服务器主键dbConcurrencyException不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中有此表格
我添加一行,并更新tableadapter.然后主键是datagridview中的14098,而同一行在服务器上具有14117.
当我再次更新时,我得到dbconcurrency异常.
主键为int,自动增量为true,并且服务器和Visual Studio属性上的种子/增量均设置为1.
请帮助
I have this form in C#
I add an row, and update tableadapter. And then the primary key is 14098 in datagridview while the same row has 14117 on the server.
When i update again i get an dbconcurrency exception.
The primary key is int and autoincremeant is true, and seed/increment is set to 1 on both server and visual studio properties.
Please help
推荐答案
在插入数据时使用身份列自动递增值时,无论是否成功插入了要插入的数据,都会始终递增.结果,标识列将具有一些空值.此页面讨论以下问题. 链接 [
When you use identity column to autoincrement value on inserting data, it will always be incremented whether the data you wanted to insert was successfully inserted or not. As a result, the identity column will have some empty values. This page discusses the following problem. Link[^]
好吧,我已经通过在tableadapter.update
之后立即设置tableadapter填充来做出解决方法.
然后使用正确的主键.但是我认为这不是一个好的解决方案.
Ok, I have made a workaround by setting tableadapter fill right after tableadapter.update
Then the right primary key is used. But i think this is no good solution.
这篇关于datagridview主键与服务器主键dbConcurrencyException不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文