DataAdapter.Update...how to handle inserts into multiple tables
When users add a new record in our app, we need to do an insert into 5 sql server tables. This insert needs to run in a transaction, and, if one insert fails, we need to do a Rollback on all the Inserts. The first 4 inserts return keys that are used as part of the last insert. Meaning, prior to doing the last insert, we need the key values from the first 4 inserts.
Our initial select returns 5 resultsets, which are stored in 5 DataTables on the client. DataRelations are built between these 5 DataTables.
Now, on an AddNew on the client, 5 Added DataRows are created, one in each of the 5 Datatables. If we use DataAdapter.Update, we have to send each DataTable seperately, therefore we cannot run the Insert as a whole, under one transaction.
Is therer a feature of DataAdapter.Update that I am not aware of that will allow us to somehow send all 5 DataTables at one time? The insert sprocs are currently written as 1:1 to each sql server table. We can easily create one sproc that executes all 5 insert sprocs, however getting the values into this main sproc is not possible unless we have one DataTable. That is if we want to use the DataAdapter.Update model.
One solution is to add all of the Added DataRows to one new custom DataTable just prior to the call to update, however this feels like a hack and I am not even sure this will work.
So, I have concluded this simply cannot be done with DataAdapter. Can anyone prove me worng?