G
G .Net
Hi Everybody
I was wondering if anybody could help me with something that has been
bothering me for some time. Basically, it is a problem I encountered some
time ago with DataSets. I found a solution (which I will refer to later) but
I have a gut feeling that there must be an easier way to do it.
In order I can explain the problem, consider the following: Suppose I have a
DataSet which has two tables "Customers" and "Orders". I set up a
relationship between both tables so that a customer can have one or many
orders. This means that "Orders" has a foreign key e.g. FK_Customer which is
copy of the primary key of the corresponding customer row. So, when I add
new orders for a customer, the new rows in the "Orders" table must have the
correct FK_Customer.
This is the problem:
When the "Customer" table is updated to the database, the primary keys of
newly added rows to this table WILL NOT in general be the same when in the
DataSet after being updated. For example, microsoft recommendes that the
primary keys in a disconnected DataSet are negative. This means that when we
come to update the "Orders" table, the values of FK_Customer will not be
correct!
As I mentioned before, I did find a solution to the problem i.e.
http://www.codeproject.com/cs/datab...asp?df=100&forumid=14883&exp=0&select=1587944
but this involves telling the child row which is its parent row (via
SetParentRow) and handling the OnRowUpdated event.
Have I been missing something? It occurs to me that this parent-child
scenario is so frequent that there must be an easier way to deal with the
situation. Has VS2005 added any new funcitonality to deal with it?
Thanks in advance
G
I was wondering if anybody could help me with something that has been
bothering me for some time. Basically, it is a problem I encountered some
time ago with DataSets. I found a solution (which I will refer to later) but
I have a gut feeling that there must be an easier way to do it.
In order I can explain the problem, consider the following: Suppose I have a
DataSet which has two tables "Customers" and "Orders". I set up a
relationship between both tables so that a customer can have one or many
orders. This means that "Orders" has a foreign key e.g. FK_Customer which is
copy of the primary key of the corresponding customer row. So, when I add
new orders for a customer, the new rows in the "Orders" table must have the
correct FK_Customer.
This is the problem:
When the "Customer" table is updated to the database, the primary keys of
newly added rows to this table WILL NOT in general be the same when in the
DataSet after being updated. For example, microsoft recommendes that the
primary keys in a disconnected DataSet are negative. This means that when we
come to update the "Orders" table, the values of FK_Customer will not be
correct!
As I mentioned before, I did find a solution to the problem i.e.
http://www.codeproject.com/cs/datab...asp?df=100&forumid=14883&exp=0&select=1587944
but this involves telling the child row which is its parent row (via
SetParentRow) and handling the OnRowUpdated event.
Have I been missing something? It occurs to me that this parent-child
scenario is so frequent that there must be an easier way to deal with the
situation. Has VS2005 added any new funcitonality to deal with it?
Thanks in advance
G