NEWBIE: Concurrency violation after switching databases?

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!

Who is Participating?
topdog770Connect With a Mentor Commented:
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];

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
BrianMc1958Author Commented:
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!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.