Concurrency Violation: updatecommand affects 0 of the expected 1 record

Source: Internet
Author: User
Dbconcurrencyexception occurs in updatecommand and deletecommand. Debugging prompt: Violation of concurrency : Deletecommand affects 0 of the expected 1 record; or Violation of concurrency : Updatecommand affects 0 of the expected 1 record.

HereViolation of concurrency: not the concurrency caused by multi-person editing.

Cause:

An exception caused by dataadapter when the number of affected rows is equal to zero during the insert, update, or delete operation.

Possible solutions:

1. check whether there is a primary key.

2 deletecommand: Check whether there is an automatic number field (Access's automatic number field may cause this exception );

Updatecommand: Check whether the original value of the updated field is null (this exception may occur when the original null value is updated ).
3. parallel operations by multiple users may also cause such exceptions.
----------------------
If you use bindingsource and tableadapter, refer to the followingCode:

Bytes -----------------------------------------------------------------------------------

Source of routine: Visual Basic. NET 2005 database programming technology and example published by People's post and telecommunications Publishing House

See: http://www.ptpress.com.cn/books/Book_Information.asp? Bid = 16271

Bytes -----------------------------------------------------------------------------------

Me. Validate ()

Me. Employee basic information bindingsource. endedit ()

Me. Employee basic information tableadapter. Update (Me. Salary Management dataset. Employee basic information. getchanges)

Me. Payroll dataset. Basic employee information. acceptchanges ()
After doing so, the dataset and database are inconsistent. Yes. acceptchanges ()
Statement.
----------------------
The response is as follows:

?
It should be processed in the rowupdating event. If a row is published and appears, it will be skipped.

We recommend that you handle the problem as follows:
If (this. Salary Management dataset. Basic employee information. getchanges! = NULL)
{Me. Basic employee information tableadapter. Update (Me. Salary Management dataset. Basic employee information. getchanges )}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.