C# -- WinForms "concurrency violation"

Posted on 2009-12-17
Last Modified: 2013-12-17
Does anyone have a fix for the below ?

 1. user #1 has DataGridView with 1,000+ records
 2. user #1 updates 20 of these records
 3. user #2 deletes one of the 20 records
 4. user #2 COMMITS delete
 5. user #1 COMMITS 20 updates
 6. user #1 gets ERROR
       ** concurrency violation the updatecommand
           affected 0 of the expected 1 records

Attached show my DataSet1.xsd
UPDATE and DELETE commands.

Basically I want a way for user #1's 19 updates to
work and get a NOTICE of the 1 failed update
and why it failed.
Question by:finance_teacher
    LVL 3

    Expert Comment

    well to make this happen you will need to work in Optimistic Concurrency Style

    i recommend you to read this:

    Author Comment

    I already use "Optimistic Concurreny Style" (attached),
    but this does not prevent the above error on DELETES.

    Please help.
    LVL 10

    Expert Comment

    I think you can force the update to continue when an error occurs by setting its ContinueUpdateOnError property to True.  This makes sure all 19 rows that are not deleted are updated correctly.

    Then, you have a RowUpdated event (on the DataAdapter) which you can use to find out, for each row individually, if the update has succeeded or not.

    Author Comment

    Please post ContinueUpdateOnError & RowUpdated event sample code.
    LVL 10

    Accepted Solution

    I have no sample code available.
    Why don't you just try it? Put a breakpoint in your code for the RowUpdated event and examine the EventArgs to find out how to detect is a row was inserted/deleted/updated successfully or which errors occurred.  There is a.Status property and a .Errors property on the EventArgs that you can use for that.

    Author Comment

    Ok, I will retest.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now