Master/Detail Transactions
From: Matt Creely (cr33d09_at_hotmail.com)
Date: 04/19/04
- Next message: Alex: "Issue with SqlCommandBuilder (Insert) when using columns names with spaces"
- Previous message: Paul Clement: "Re: Reading data via field names vs ordinals"
- Next in thread: David Sceppa: "RE: Master/Detail Transactions"
- Reply: David Sceppa: "RE: Master/Detail Transactions"
- Messages sorted by: [ date ] [ thread ]
Date: 19 Apr 2004 07:39:31 -0700
I have an n-Tier Intranet application. One of the pages in the site
needs to do multiple updates, deletes, inserts, all in one big
transaction. If any of the updates fails, then everything must be
rolled back. To complicate the issue, these records contain a
master/detail relationship. So, if I create the master record, say
"Order", I have to also create the detail record, call it
"OrderDetail", which uses the OrderID as it's foreign key to Order.
Also, the field "OrderID" in the master table is an identity field in
sql 2000.
So, for example, the user makes some changes to this page, and clicks
"Save". An example use case as follows:
1. Delete Order (OrderID=213) and any Order Details pertaining to it.
2. Insert New Order (OrderID=@@Identity) and create 3 OrderDetail
records, using @@Identity, and some other info.
3. Update Order (OrderID=217) with some info.
4. Delete Order (OrderID-219) and BOOM!!! FK VIOLATION OR SOMETHING
ROLL BACK ALL CHANGES!
Is this possible? Using an ado.net dataset looks like the magic
bullet. If I can create a dataset, make all of these changes, and then
attempt to run the transaction as an ADO.net SqlTransaction, that
would be very nice. I'm not sure how'd I'd do it in T-SQL, having to
pass in arrays of detail records into a stored procedure. I've done
all sorts of transaction work before, using ADO.Net (and T-SQL), but I
just don't know how to deal with the Master/Detail relationship. Does
the OrderID field need to be generated by my system? Or can I still
accomplish this with an Identity Field?
It'd be really nice to just say:
DataSet.Tables(1).Rows(y).Item("OrderID") =
DataSet.Tables(0).Rows(x).Item("OrderID")
- Next message: Alex: "Issue with SqlCommandBuilder (Insert) when using columns names with spaces"
- Previous message: Paul Clement: "Re: Reading data via field names vs ordinals"
- Next in thread: David Sceppa: "RE: Master/Detail Transactions"
- Reply: David Sceppa: "RE: Master/Detail Transactions"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|