RejectChanges doesn't rollback the autonumber (I understand why thanks to this post). But, when I save a row. It overrides the autonumber which was originally returned to me. I need to know the ID of the parent row so I can create the related records.
Perhaps there is a better way I should be creating the related rows?
I saw this post which recommended changing the AutoIncrement to -1 and AutoSeed to -1. But, that does't make sense nor did it work for me.
In my code there are two tables, Shipments and Shipment_Package_Details. It's a 1-many relationship.
r = this.allertDataSet3.Shipments.NewShipmentsRow();
log.Debug("The new ShipmentRow ID is " + r.ShipmentID); // ID == 1
this.allertDataSet3.Shipments.RejectChanges();
r = this.allertDataSet3.Shipments.NewShipmentsRow();
log.Debug("The new ShipmentRow ID is " + r.ShipmentID); // ID == 2
r.NumPkgs = p.Length;
this.allertDataSet3.Shipments.Rows.Add(r);
// Create Related Row
MyCompany.MyNamespace.allertDataSet3.Shipment_Package_DetailsRow pd = this.allertDataSet3.Shipment_Package_Details.NewShipment_Package_DetailsRow();
pd.ShipmentID = r.ShipmentID; // ID == 2 here.
pd.TrackingNumber = trackingNumbers[i];
this.allertDataSet3.Shipment_Package_Details.Rows.Add(pd);
this.shipmentsTableAdapter.Update(this.allertDataSet3);
// At this point if i set a breakpoint and look at database, it's been committed to the database with ID == 1.
// The following line will fail since I set the package details row to ID == 2.
this.shipment_Package_DetailsTableAdapter.Update(this.allertDataSet3);