Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Concurrency violation: the UpdateCommand affected 0 of the expected 1 records [Very Emergency]

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records [Very Emergency]

Scheduled Pinned Locked Moved C#
helpannouncement
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    hi i'm using TableAdapter to update data, but when i use TableAdapterManager to update, the following exception occure :

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

    i have some trouble with this operation and i've a lot of search over internet and could not solved my problem. also microsoft has a video to demonstrate this, but when i try that, i still get this exception. Any help would be great appreciated.

    R 1 Reply Last reply
    0
    • H hdv212

      hi i'm using TableAdapter to update data, but when i use TableAdapterManager to update, the following exception occure :

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

      i have some trouble with this operation and i've a lot of search over internet and could not solved my problem. also microsoft has a video to demonstrate this, but when i try that, i still get this exception. Any help would be great appreciated.

      R Offline
      R Offline
      Roman Lerman
      wrote on last edited by
      #2

      I found this, may bee it's helps. Make sure you don't modify the access database anywhere in your code without going through the datatable, because if you do the data in the datatable will no longer be synchronized with the database.

      H 1 Reply Last reply
      0
      • R Roman Lerman

        I found this, may bee it's helps. Make sure you don't modify the access database anywhere in your code without going through the datatable, because if you do the data in the datatable will no longer be synchronized with the database.

        H Offline
        H Offline
        hdv212
        wrote on last edited by
        #3

        Hi Roman can u more explain ? i have a simple form with simple dataBinding. that's it. Here is my code :

        private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
        this.Validate();
        this.customersBindingSource.EndEdit();
        this.ordersBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.test2DataSet);
        }

            private void Form2\_Load(object sender, EventArgs e)
            {
                this.customersTableAdapter.Fill(this.test2DataSet.Customers);
                this.ordersTableAdapter.Fill(this.test2DataSet.Orders);            
            }
        
            private void ordersBindingSource\_AddingNew(object sender, AddingNewEventArgs e)
            {
                this.customersBindingSource.EndEdit();
            }
        

        Note : Customers is parent Table and Orders is child Table

        R 1 Reply Last reply
        0
        • H hdv212

          Hi Roman can u more explain ? i have a simple form with simple dataBinding. that's it. Here is my code :

          private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
          {
          this.Validate();
          this.customersBindingSource.EndEdit();
          this.ordersBindingSource.EndEdit();
          this.tableAdapterManager.UpdateAll(this.test2DataSet);
          }

              private void Form2\_Load(object sender, EventArgs e)
              {
                  this.customersTableAdapter.Fill(this.test2DataSet.Customers);
                  this.ordersTableAdapter.Fill(this.test2DataSet.Orders);            
              }
          
              private void ordersBindingSource\_AddingNew(object sender, AddingNewEventArgs e)
              {
                  this.customersBindingSource.EndEdit();
              }
          

          Note : Customers is parent Table and Orders is child Table

          R Offline
          R Offline
          Roman Lerman
          wrote on last edited by
          #4

          1: try to remove -> this.customersBindingSource.EndEdit(); <- from ordersBindingSource_AddingNew(). or 2: modify private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.customersBindingSource.EndEdit(); this.ordersBindingSource.EndEdit(); DataTable changes = null; changes = your datatable here.GetChanges(); if (changes != null) { TableAdapter.Update(changes); } your datatable heree.AcceptChanges(); }

          H 1 Reply Last reply
          0
          • R Roman Lerman

            1: try to remove -> this.customersBindingSource.EndEdit(); <- from ordersBindingSource_AddingNew(). or 2: modify private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.customersBindingSource.EndEdit(); this.ordersBindingSource.EndEdit(); DataTable changes = null; changes = your datatable here.GetChanges(); if (changes != null) { TableAdapter.Update(changes); } your datatable heree.AcceptChanges(); }

            H Offline
            H Offline
            hdv212
            wrote on last edited by
            #5

            As u can see in my above code, i'm using TableAdapterManager, not TableAdapter!

            R 1 Reply Last reply
            0
            • H hdv212

              As u can see in my above code, i'm using TableAdapterManager, not TableAdapter!

              R Offline
              R Offline
              Roman Lerman
              wrote on last edited by
              #6

              If you use TableAdapterManager your project contain TableAdapters, so try to use them. Sorry for my English.

              H 1 Reply Last reply
              0
              • R Roman Lerman

                If you use TableAdapterManager your project contain TableAdapters, so try to use them. Sorry for my English.

                H Offline
                H Offline
                hdv212
                wrote on last edited by
                #7

                i've use this commands :

                Test2DataSet.CustomersDataTable customerChanges = null;
                Test2DataSet.OrdersDataTable orderChanges = null;

                        customerChanges = (Test2DataSet.CustomersDataTable)this.test2DataSet.Customers.GetChanges();
                        orderChanges = (Test2DataSet.OrdersDataTable)this.test2DataSet.Orders.GetChanges();
                
                        if (customerChanges != null)
                            this.customersTableAdapter.Update(customerChanges);
                        this.test2DataSet.Customers.AcceptChanges();
                
                        if (orderChanges != null)
                            this.ordersTableAdapter.Update(orderChanges); **// Error has been occured in this line**
                        this.test2DataSet.Orders.AcceptChanges();
                

                but i got this exception :

                The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Orders_Customers". The conflict occurred in database "Test2", table "dbo.Customers", column 'CustomerID'.
                The statement has been terminated.

                R 1 Reply Last reply
                0
                • H hdv212

                  i've use this commands :

                  Test2DataSet.CustomersDataTable customerChanges = null;
                  Test2DataSet.OrdersDataTable orderChanges = null;

                          customerChanges = (Test2DataSet.CustomersDataTable)this.test2DataSet.Customers.GetChanges();
                          orderChanges = (Test2DataSet.OrdersDataTable)this.test2DataSet.Orders.GetChanges();
                  
                          if (customerChanges != null)
                              this.customersTableAdapter.Update(customerChanges);
                          this.test2DataSet.Customers.AcceptChanges();
                  
                          if (orderChanges != null)
                              this.ordersTableAdapter.Update(orderChanges); **// Error has been occured in this line**
                          this.test2DataSet.Orders.AcceptChanges();
                  

                  but i got this exception :

                  The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Orders_Customers". The conflict occurred in database "Test2", table "dbo.Customers", column 'CustomerID'.
                  The statement has been terminated.

                  R Offline
                  R Offline
                  Roman Lerman
                  wrote on last edited by
                  #8

                  Try this: this.Validate(); this.customersBindingSource.EndEdit(); this.ordersBindingSource.EndEdit(); Test2DataSet.CustomersDataTable customerChanges = null; Test2DataSet.OrdersDataTable orderChanges = null; customerChanges = (Test2DataSet.CustomersDataTable)this.test2DataSet.Customers.GetChanges(); orderChanges = (Test2DataSet.OrdersDataTable)this.test2DataSet.Orders.GetChanges(); if (customerChanges != null) this.customersTableAdapter.Update(customerChanges); if (orderChanges != null) this.ordersTableAdapter.Update(orderChanges); // Error has been occured in this line this.tableAdapterManager.UpdateAll(this.test2DataSet);

                  H 1 Reply Last reply
                  0
                  • R Roman Lerman

                    Try this: this.Validate(); this.customersBindingSource.EndEdit(); this.ordersBindingSource.EndEdit(); Test2DataSet.CustomersDataTable customerChanges = null; Test2DataSet.OrdersDataTable orderChanges = null; customerChanges = (Test2DataSet.CustomersDataTable)this.test2DataSet.Customers.GetChanges(); orderChanges = (Test2DataSet.OrdersDataTable)this.test2DataSet.Orders.GetChanges(); if (customerChanges != null) this.customersTableAdapter.Update(customerChanges); if (orderChanges != null) this.ordersTableAdapter.Update(orderChanges); // Error has been occured in this line this.tableAdapterManager.UpdateAll(this.test2DataSet);

                    H Offline
                    H Offline
                    hdv212
                    wrote on last edited by
                    #9

                    I've Copy/Paste your code in my app :

                    this.Validate();
                    this.customersBindingSource.EndEdit();
                    this.ordersBindingSource.EndEdit();

                            Test2DataSet.CustomersDataTable customerChanges = null;
                            Test2DataSet.OrdersDataTable orderChanges = null;
                    
                            customerChanges = (Test2DataSet.CustomersDataTable)this.test2DataSet.Customers.GetChanges();
                            orderChanges = (Test2DataSet.OrdersDataTable)this.test2DataSet.Orders.GetChanges();
                    
                            if (customerChanges != null)
                                this.customersTableAdapter.Update(customerChanges);
                    
                            if (orderChanges != null)
                                this.ordersTableAdapter.Update(orderChanges); // Error has been occured in this line
                    
                            this.tableAdapterManager.UpdateAll(this.test2DataSet);
                    

                    but i still got this error :

                    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Orders_Customers". The conflict occurred in database "Test2", table "dbo.Customers", column 'CustomerID'.
                    The statement has been terminated.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups