[已解决]并发冲突:更新了预期的1条记录中的0条 [英] [Solved] concurrency violation : Updated 0 of the expected 1 records

查看:94
本文介绍了[已解决]并发冲突:更新了预期的1条记录中的0条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我尝试使用C#中的Dataadapter.update方法更新数据库表时,抛出错误并发冲突:更新了预期的1条记录中的0。 />
请帮我解决这个问题。



问候,

Ramakrishna



来自OP的更新:

OP能够自己解决问题。发布解决方案作为答案之一。

解决方案

HI全部,

我通过指定datatable.acceptchanges()解决了这个问题。 br />
一旦完成,将每行的添加属性设置为true,你就可以正确使用应用程序。

感谢所有回复。


大家好,

这个博客 http://blogs.msdn.com/b/spike/archive/2010/04/07/concurrency-violation-the-updatecommand-受影响的0-of-expected-1-records.aspx [ ^ ]

定义原因相关问题,但最具体的原因可以从msdn http://msdn.microsoft.com/en-us/library/cs6hb8k4.aspx [ ^ ]



取自msdn

Quote:

尝试更新时,将更改行的原始版本与数据库中的现有行。如果两者不同,则更新失败并出现并发错误。在那时你可以使用你创建的业务逻辑来协调这两行。





一个例子来说明

在下面的SQL'modifiedOn'数据时间列已被重新检索并已更改为varchar以显示用户

引用:

从TableName中选择名称,角色,转换(varchar,modifiedOn,105)作为modifiedOn



现在,当UI端用户更新行时,可以说名称并在DB上执行行更新,它将无法给出并发冲突错误,因为modifiedOn列未被修改,并且与数据库中的现有行不同。


< blockquote>嘿Ramakrishna,



我经历过这个例外的大部分时间都是自动更新数据集(或数据表)中的一列或多列时,或者数据库为一个或多个字段提供不同的值由于触发器。



我有一个带有DateCreated和DateModified字段的表。使用SQL Server数据库中的更新触发器填充DateModified字段。这导致了并发声音。我希望这会有所帮助。



祝你好运,

Eduard


Hi All,
When i am trying to update the database table using the Dataadapter.update method in C#, throws the error "concurrency violation : Updated 0 of the expected 1 records".
Please help me how to get this resolved.

Regards,
Ramakrishna

UPDATE from OP:
OP was able to resolve he issue by himself. Posted resolution as one of the answers.

解决方案

HI All,
I got this resolved by specifying the datatable.acceptchanges().
once this is done set added property of each row to true and you are there with the correct working of application.
Thanks all for the replies.


Hi All,
This blog http://blogs.msdn.com/b/spike/archive/2010/04/07/concurrency-violation-the-updatecommand-affected-0-of-the-expected-1-records.aspx[^]
defines the cause of the related problem, however most specifically the cause can be best understand from the msdn http://msdn.microsoft.com/en-us/library/cs6hb8k4.aspx[^]

Taken from msdn

Quote:

When an update is attempted, the original version of a changed row is compared against the existing row in the database. If the two are different, the update fails with a concurrency error. It is up to you at that point to reconcile the two rows, using business logic that you create.



An example to illustrate
In below SQL 'modifiedOn' datatime column has been retrived and has been changed to varchar to display it the users

Quote:

select top 1 Name, Role, convert(varchar, modifiedOn, 105) as modifiedOn from TableName


Now when the UI side user updates the row lets say 'Name' and do an row update on the DB, it will fail giving the concurrency violation error, because of the column 'modifiedOn' it is not modified and it is different against the existing row in the database.


Hey Ramakrishna,

Most of the time's I've experienced this exception was when one or more columns in the dataset (or datatable) to be updated are automated, or the database gives one or more fields different values due to triggers.

I had tables with a DateCreated and a DateModified field. The DateModified field was populated using a update trigger in the SQL Server database. This caused the concurrency voilation. I hope this helps.

Good Luck,
Eduard


这篇关于[已解决]并发冲突:更新了预期的1条记录中的0条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆