none
DBConcurrencyException RRS feed

  • Question

  • I am getting following Error

    Concurrency Violation : the update command affected 0 of the expected 1 records'.

    I am using VB 2008 & MS Access Databases for WinForm Application having Typed DataSets & Bound Controls.

    Adding first record is Fine but after updating 1st if i add another record & try to Update then i get above error messege.

    I have tried couple of ways to trace the prob. but nothing come out.

    In the new form if i drag a same DataTable from dataset & run the form without any user code the app runs fine & u may add n no. of records in the form in one go. however after some code is added to the form the app start giving error,

    I have no field in DB set to unique.

    Friday, April 1, 2011 8:15 PM

Answers

  • Hello Jackie

    One thing i want to tell you is that the app. is single user application & no one else is changing the original record in any way.

    Now my question is my 1st added Record gets updated correctly & no checking is done with DB till that time only by 2nd Record being added the checking of fields with DB starts why?

    Again with a fresh new Form if i Drag DataTable onto form having default code generated by VB, if i run the form & enter new records, no Errors are thrown why that?

    One more thing i want to share you that i have another forms having Diffrent Data Table from same Database but no column set to AutoNumber column. In this forms i do generate the Primary key value through code that is by calling Max value of that column plus 1, i do so every time i add a new record to binding source with such scenerio i never get Concurrency Errors.

     

    Tuesday, April 5, 2011 5:47 PM
  • I HAVE FOUND THE PROB. WHERE IS

    I have a Binding Navigator where i have a Add, Delete & Save Buttons where Add & Delete buttons have there code hidden & Save button code visible to me.

    Now that i added the Following code to Add Button which gave me Exception

     

    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click

    MDI.lblStatusLabel1.Text =

    "ADDING NEW"
     

    txtPartyName.Focus()

     

    End Sub

    i dont know why it gives Error but i simply added the AddNew method to code & Set the BindingNavigators AddNewItem to (None) & that solves the problem.

    here the new Code

     

    Private

     

    Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

    btnAddNew.Click

    bsCreditors.AddNew()

    MDI.lblStatusLabel1.Text =

    "ADDING NEW"

    txtPartyName.Focus()

     

    End

    Sub

    Tuesday, April 12, 2011 12:26 AM

All replies

  • Hello SANDEEP,

     

    Welcome to the MSDN Forum!

    I think the reason that happened is the UPDATE statement created by the CommandBuilder object uses the values stored in the copy of the DataRow with a DataRowVersion value of Original to identify and update the appropriate row in the database. the CommandBuilder creates a SQL statement that looks for a row which exactly matches all of the original values stored in the DataSet means the value of each and every column in the row is checked. if you are trying to update a row that no longer exists in the database, the update from the DataAdapter will fail with the above exception.

    We should create Command objects for the UpdateCommand of each of the DataAdapters. Write Update SQL query, create command object and set it as a dataadapter updatecommand.

    See also:

    http://blogs.msdn.com/b/spike/archive/2010/04/07/concurrency-violation-the-updatecommand-affected-0-of-the-expected-1-records.aspx

    http://techbrij.com/514/concurrency-violation-the-updatecommand-affected-0-of-the-expected-1-records

    I hope this can help you.

     

    Have a nice day,
     


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 4, 2011 6:44 AM
    Moderator
  • Hello Jackie

    One thing i want to tell you is that the app. is single user application & no one else is changing the original record in any way.

    Now my question is my 1st added Record gets updated correctly & no checking is done with DB till that time only by 2nd Record being added the checking of fields with DB starts why?

    Again with a fresh new Form if i Drag DataTable onto form having default code generated by VB, if i run the form & enter new records, no Errors are thrown why that?

    One more thing i want to share you that i have another forms having Diffrent Data Table from same Database but no column set to AutoNumber column. In this forms i do generate the Primary key value through code that is by calling Max value of that column plus 1, i do so every time i add a new record to binding source with such scenerio i never get Concurrency Errors.

     

    Tuesday, April 5, 2011 5:47 PM
  • I HAVE FOUND THE PROB. WHERE IS

    I have a Binding Navigator where i have a Add, Delete & Save Buttons where Add & Delete buttons have there code hidden & Save button code visible to me.

    Now that i added the Following code to Add Button which gave me Exception

     

    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click

    MDI.lblStatusLabel1.Text =

    "ADDING NEW"
     

    txtPartyName.Focus()

     

    End Sub

    i dont know why it gives Error but i simply added the AddNew method to code & Set the BindingNavigators AddNewItem to (None) & that solves the problem.

    here the new Code

     

    Private

     

    Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

    btnAddNew.Click

    bsCreditors.AddNew()

    MDI.lblStatusLabel1.Text =

    "ADDING NEW"

    txtPartyName.Focus()

     

    End

    Sub

    Tuesday, April 12, 2011 12:26 AM