Concurrency Violation When Updating MS Access Db

I am working on a VB .Net 2005 application with a MS Access database backend. I am able to add a new row to a datatable via a DataGridView control. After invoking the Update method on the TableAdapter, I have verified the new row is written to the Access database with the values I've entered. This problem is I get a concurrency violation error when attempting to save (update) a subsequent edit of the newly added row. I am the only person making edits to this database. This row does contain an autonumber field. Making the TableAdapter.Fill call again to refresh the datatable after initially adding the row corrects the problem, but seems inefficient and causes the selected item in the grid control to be reset. I suspect I need to refresh my datatable to get the new primary key value, just wondering if someone could help provide some guidance on a preferred method to correct this issue. Thanks!



Answer this question

Concurrency Violation When Updating MS Access Db

  • Christian Reizlein

    Hi,

    Sorry for the delay. Your problem is that you probably don't fetch new Category_Id (autoinc field, right ).

    So, you migth read
    Retrieving Identity or Autonumber Values
    in .net help files.



  • David Lam

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1316022&SiteID=1&mode=1
  • Kris_Jana

    I guess your TableAdapter is not well configured. I also assume that it does compare all non-primary key fields when updating and if one of those fields has a different value than the one in database you get concurrency exception. Perhaps you might look at TableAdapter.Update command definition in source file.

  • Amit Chattopadhyay

    Thanks for the response. My tableadapter definition was created by the dataset designer. I looked at the insert and update string for the tableadapter, looks ok to me - but I'm a newbie. Here they are:

    INSERT INTO Category
    (Category_Name, Category_Order, Program_ID, Category_Option)
    VALUES ( , , , )


    UPDATE Category
    SET Category_Name = , Category_Order = , Program_ID = , Category_Option =
    WHERE (Category_ID = ) AND ( = 1 AND Category_Name IS NULL OR
    Category_Name = ) AND ( = 1 AND Category_Order IS NULL OR
    Category_Order = ) AND ( = 1 AND Program_ID IS NULL OR
    Program_ID = ) AND ( = 1 AND Category_Option IS NULL OR
    Category_Option = )

    Although my database is updated with the new autonumber key for this row, the datagridview still displays "-1" for the key value of the new row. The subsequent update of other non-key attributes in the new row containing the "-1" key value result in the concurrency error. Any ideas


  • Concurrency Violation When Updating MS Access Db