Concurrency violation: the UpdateCommand affected 0 of the expected 1 records [Very Emergency]
-
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.
-
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.
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.
-
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.
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
-
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
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(); }
-
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(); }
-
If you use TableAdapterManager your project contain TableAdapters, so try to use them. Sorry for my English.
-
If you use TableAdapterManager your project contain TableAdapters, so try to use them. Sorry for my English.
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. -
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.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);
-
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);
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.