D
Dmitry Sazonov
Please, somebody help me. DataAdapter is not adding fields to tables with
"auto increment" ID :-( :-(
I have 2 related tables, let say, table "Orders" and table "OrderDetails"
--------------------------------
| Orders
| - - - - - - - - - - - - - - -
| ID int, autoincrement, primary key
| ...
--------------------------------
--------------------------------
| OrderDetails
| - - - - - - - - - - - - - - -
| OrderID int, (related to field ID in table Orders)
| ...
--------------------------------
// ------- Now, I create DataRow for orders and adding it to DataSet:
OrdersRow order = ds.Orders.NewOrdersRow();
order.Name = ...; // etc, set all properties
ds.AddOrdersRow( order );
// --- at this moment "order.ID" have some value, let say 1000
// ------- then I'm creating order details
OrderDetailsRow od = ds.Orders.NewOrderDetailsRow();
od.OrderID = order.ID;
ds.AddOrderDetailsRow( od );
// --- everything is still good
// -------- now I'm commiting changes:
OrdersAdapter.Update( ds.Orders ); // --- it worked fine.
// But my new order added to database with different ID, let say 1002.
// It could be any number, even 1000, in this case there will be
no error.
// But it could be more than 1000 and I get the error
//
// Database remember last ID and adds record with this number.
// at this moment, in memory object "ds.Orders" contains different
information
// from data source
// if I will try to add OrderDetails to database,
OrderDetailsAdapter.Update( ds.OrderDetails ); // --- exeption !!!
I will get error "You cannot add or change a record because a related record
is requred in table 'Orders' "
"auto increment" ID :-( :-(
I have 2 related tables, let say, table "Orders" and table "OrderDetails"
--------------------------------
| Orders
| - - - - - - - - - - - - - - -
| ID int, autoincrement, primary key
| ...
--------------------------------
--------------------------------
| OrderDetails
| - - - - - - - - - - - - - - -
| OrderID int, (related to field ID in table Orders)
| ...
--------------------------------
// ------- Now, I create DataRow for orders and adding it to DataSet:
OrdersRow order = ds.Orders.NewOrdersRow();
order.Name = ...; // etc, set all properties
ds.AddOrdersRow( order );
// --- at this moment "order.ID" have some value, let say 1000
// ------- then I'm creating order details
OrderDetailsRow od = ds.Orders.NewOrderDetailsRow();
od.OrderID = order.ID;
ds.AddOrderDetailsRow( od );
// --- everything is still good
// -------- now I'm commiting changes:
OrdersAdapter.Update( ds.Orders ); // --- it worked fine.
// But my new order added to database with different ID, let say 1002.
// It could be any number, even 1000, in this case there will be
no error.
// But it could be more than 1000 and I get the error
//
// Database remember last ID and adds record with this number.
// at this moment, in memory object "ds.Orders" contains different
information
// from data source
// if I will try to add OrderDetails to database,
OrderDetailsAdapter.Update( ds.OrderDetails ); // --- exeption !!!
I will get error "You cannot add or change a record because a related record
is requred in table 'Orders' "