Non-skipping IDs with Master-Detail
- From: "Michelle Brennan" <mibi222@xxxxxxxxxxx>
- Date: 23 Oct 2005 13:30:38 -0700
I've been looking quite a while for a solution to this and I'm
still having a lot of trouble, so please help me!
I'm creating an Order form app using ADO and SQL Server. I want
to use BatchOptimistic so the user can cancel or apply the
order after all master and detail information has been entered.
I've created a table called KeyTable which will store the next
master key (Order Number). I'm NOT using an IDENTITY/AutoInc
field. I have a function called GetNextKey() that uses TADOQry
to SELECT the next order number key and then UPDATE the column
to increment the key by 1.
The master and detail tables are linked: datasetDetail's
MasterFields property. This works fine when browsing or editing
but NOT when inserting (see below).
Also, the order number (master ID) CANNOT SKIP, so from what I
read, I'm only supposed to set the next key right before
UpdateBatch to minimize conflicts in a multi-user environment.
I issue a BeginTransaction right before calling my GetNextKey
function (which also increments the key). This way, if the user
aborts the order, everything gets rolled back at once.
When placing a NEW order, after I issue a POST command (not
UpdateBatch) on the DETAIL table, the record just disappears,
as if the foreign key was not set. I can't set the MASTER key
right away (using my GetNextKey function) because if another
user creates a new order simultaneously, they would both get
the same ID since UpdateBatch hasn't been called yet and
the transaction has not been commited.
On the other hand, if I call UpdateBatch up front, and the user
aborts the order, the ID has already been used, and the Order
number will skip.
I tried creating an IDENTITY field to hold an internal ID just
for Master-detail link and create a separate OrderNumber field,
but the master-detail link still doesn't work when inserting a
new order.
Somebody PLEASE help me. I really need to find a solution to
this as soon as possible!
Sorry for the long post.
.
- Follow-Ups:
- Re: Non-skipping IDs with Master-Detail
- From: Brian Bushay TeamB
- Re: Non-skipping IDs with Master-Detail
- From: Kostas Terzides
- Re: Non-skipping IDs with Master-Detail
- Prev by Date: Re: UpdateBatch or Post changes state to dsBrowse
- Next by Date: Re: Non-skipping IDs with Master-Detail
- Previous by thread: Testing for TABLE in database
- Next by thread: Re: Non-skipping IDs with Master-Detail
- Index(es):
Relevant Pages
|