NEWBIE: Concurrency violation after switching databases?

Posted on 2006-06-05
Medium Priority
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
  • 2
LVL 12

Expert Comment

ID: 16833446
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

ID: 16833547
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

topdog770 earned 1000 total points
ID: 16846961
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];


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, left to enroll

840 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