J
joben
I need help with the following. I'm a newbie.
I have a master-detail form for an inventory application. Its a simple
form to record delivered items. The underlying table schema is as
follows
(simplified):
DELIVERY
-DeliveryID (Integer, PK, Identity)
DELIVERYDETAILS
-DeliveryFK
-SerialNumber
The dataset has the corresponding tables with a declared data relation
for linking DeliveryID and DeliveryFK. In the dataset schema, I set
(-1) as a default value for both DeliveryID and DeliveryFK. I use a
data adapter to propagate changes to the DB. In my insert command, I've
set the .UpdatedRowSource = OutputParameters so that when I insert into
the Delivery table, I can retrieve the generated PK. The data relation
takes care of cascading the value to DeliveryFK. So far so good. I am
able to successfully insert to both DELIVERY and DELIVERYDETAILS.
My problem is that after I save the records, I want the user to be able
to update the same record, or insert new details. As long as no new
details are added, I can still update the underlying records. But when
I add new details, I get an error. "violation of foreign key
constraint". What happens is that when I add new details, the
DeliveryFK has a value of (-1) because that is the default value I
initially set. But the DeliveryID already has a different value because
during the INSERT, I was able to retrieve the generated PK.
How do I tell my dataset to use the new value of DeliveryFK instead of
the default?
Thanks for any help.
I have a master-detail form for an inventory application. Its a simple
form to record delivered items. The underlying table schema is as
follows
(simplified):
DELIVERY
-DeliveryID (Integer, PK, Identity)
DELIVERYDETAILS
-DeliveryFK
-SerialNumber
The dataset has the corresponding tables with a declared data relation
for linking DeliveryID and DeliveryFK. In the dataset schema, I set
(-1) as a default value for both DeliveryID and DeliveryFK. I use a
data adapter to propagate changes to the DB. In my insert command, I've
set the .UpdatedRowSource = OutputParameters so that when I insert into
the Delivery table, I can retrieve the generated PK. The data relation
takes care of cascading the value to DeliveryFK. So far so good. I am
able to successfully insert to both DELIVERY and DELIVERYDETAILS.
My problem is that after I save the records, I want the user to be able
to update the same record, or insert new details. As long as no new
details are added, I can still update the underlying records. But when
I add new details, I get an error. "violation of foreign key
constraint". What happens is that when I add new details, the
DeliveryFK has a value of (-1) because that is the default value I
initially set. But the DeliveryID already has a different value because
during the INSERT, I was able to retrieve the generated PK.
How do I tell my dataset to use the new value of DeliveryFK instead of
the default?
Thanks for any help.