NEWBIE: Concurrency violation after switching databases?

Posted on 2006-06-05
Last Modified: 2008-03-10
Dear Experts,

I'm a total newbie at VS2005 and C#.  I'm writing a quickie app which will allow an in-house user to switch between working with the "same" table in a test and a production database.  (The table has the same definition, with different data.)

When I open the app, I set the Database to "test".  Then, I let the user change it to "production".  So far, that works.  I see the "production" table come up.  However, when I try to Update the "production" table, I get this error:

  Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

There are definitely no other users of either table.  The Update on the original "test" table works fine.  

This is the code I use to perform the Update:

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)

This is the code I use to switch databases:

        private void databasesToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
            String curDb = e.ClickedItem.Text;

I should emphasize that I am a complete idiot at this point, and I'm probably missing something obvious!

Question by:BrianMc1958
    LVL 12

    Expert Comment

    One thing that I've done to cause this it to call the AcceptChanges function prior to doing an update.

    Also, now that I think about it.. no morning coffee, yet, is that by changing tables... the adapter doesn't know how to synch things up... I think I've used clone or merge to get around this issue.

    Will take a quick look

    Author Comment

    I tried AcceptChanges (on "myTable") prior to the update, and it removed the error, but nothing was actually updated in the table.

    And yes, I'm assuming I'm causing confusion by changing tables (and databases) in mid-stream.  PLEASE have your morning coffee!

    LVL 12

    Accepted Solution

    and then to top it all off... experts-exchange emails starting going to my junk folder.  sorry for delay.

    I've done stuff like:  off top o' head.. syntax may not be 100%

    DataTable NewTable = OldTable.Clone();  

    for( int iRowCount=0; iRowCount < OldTable.Rows.Count; iRowCount++)
      NewTable.Row.ImportRow( OldTable.Rows[iRowCount];


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    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…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    794 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

    14 Experts available now in Live!

    Get 1:1 Help Now