Using UpdateDataSet from Enterprise Library January 2006

H

H

I call a function with a CustomerID and it returns a dataset of two
tables (Customers, Orders).
If the ID does not exist in Customers, it returns empty tables.
I also set a relationship on CustomerID between the tables, as well as
a constraint on CustomerID.

In code, if the tables are empty, I add a new row to the Customers
table where I set the Customer details
(the primary key 'CustomerID' will be set automatically).
Then, I add a new row to the Orders table, where I set the Order
details (the primary key 'OrderID' will be set
automatically). In that new row, I also set the foreign key column of
CustomerID to -1, so that it will
be filled with the automatically created CustomerID.

Using Enterprise Library, I call UpdateDataSet once with the main
dataset and 'Customers' table as parameters,
then I call UpdateDataSet again with the main dataset and 'Orders'
table as parameters.
(Using appropriate stored procedures)

The first UpdateDataSet call works, it creates the Customer record and
gives it a new CustomerID.
However, when I call the second UpdateDataSet, the CustomerID value is
still -1 and I get the error:

Insert statement conflicted with Column Foreign Key constraint
'FKOrders_Customers'.
The conflict occurred in database 'main', table 'Customers', column
'UDFID'.

How can I update both tables at once so that the foreign key in Orders
gets filled with the proper value?

Thanks!!!!
 
H

H

the above error msg should say

Insert statement conflicted with Column Foreign Key constraint
'FKOrders_Customers'.
The conflict occurred in database 'main', table 'Customers', column
'CustomersID'.

I mistyped the column in the error msg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top