Click here to Skip to main content
15,896,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Visual Studio 2013 and I am creating my project in VB.Net. I have a simple vb.net form with three text fields that are bound to an Access database data source. (The database does have a primary key.) The concurrency violation occurs when I run the project, add a record and save it, make a change to the same record and then save it. The full error message reads:

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. Include logic in your application to handle concurrency violations.

I am new to VB.Net and I desperately need help with the logic to handle the concurrency violations. I will greatly appreciate any help with the code involved in fixing this issue.
Posted
Updated 1-Mar-18 18:21pm
v2
Comments
Maciej Los 14-Apr-15 1:54am    
Not enough information...

Please, read my comment to the question.

MSDN wrote:
Concurrency exceptions (DBConcurrencyException) are raised when two users attempt to change the same data in a database at the same time. In this walkthrough you create a Windows application that illustrates catching a DBConcurrencyException, locating the row that caused the error, and one strategy for you can use for handling it.


source: Walkthrough: Handling a Concurrency Exception[^]

See also: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.[^]
 
Share this answer
 
I am the original poster of the concurrency question. Here is how I solved the concurrency violation issue in my application. It may not be appropriate in other applications. But it may help other new users.

My application is for a single user. Therefore, there will never be the instance where two users will by trying to change a record in the database table at the same time. So I do not need to catch concurrency violations. The concurrency violation error was being thrown in my application when I entered data, saved the record, and then modified the record and saved it again. It was frustrating to have the program throw an error when there wasn't a situation where two users where changing the same record. I was making a modification to something that I just entered, and that is what I wanted.

VB
'Save Changes to Records
   Private Sub TblAssetDataBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblAssetDataBindingNavigatorSaveItem.Click
       Me.Validate()
       Me.TblAssetDataBindingSource.EndEdit()
       Me.TableAdapterManager.UpdateAll(Me.AssetDatabaseDataSet)
       Me.TblAssetDataTableAdapter.Fill(Me.AssetDatabaseDataSet.tblAssetData)

   End Sub
 
Share this answer
 
Since my application is a single user application, there is no reason for the code to check for concurrency issues when the user saves a change they made to a record in the database. Therefore, I just use On Error Resume Next in the form's Save event to avoid the annoying concurrency error message.

The concurrency error message was occurring in my application when the user entered data into the form, then saved the change, and subsequently modified that same record, and then saved it again. Obviously, if the same user makes a change to a record that they just saved, they want to save the updated record and there is no concurrency issue.
 
Share this answer
 
v2
Comments
Member 13246482 7-Jun-17 16:40pm    
Thanks for posting your fix. I was having same problem and your solution fixed my problem also. Thanks again for taking the time to post the fix.
WillingMost7 20-Jun-22 10:36am    
Sorry for asking in such an old question, but that's exactly my problem. I didn't quite catch how did you fix it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900