
Signature
Val Mazur
Microsoft MVP
http://xport.mvps.org
> I'm afraid I don't see how that example solves my problem. Could you be
> more specific about it? Thank you.
[quoted text clipped - 116 lines]
>>> Regards,
>>> David.
Well, you're right about it has to do with indentity values, but the example
does not solve my problem (or atleast I don't see it do so). I'll try to
explain my problem in another way.
There are two users. Both recieving data into their datasets. They both
modify the same row in table A. This row has a column value that refeers to
a row in table B. At first the value of this column is NULL (there is no row
in table B yet). Both users then add a row to table B. The value of the Id
column of this row is then put in the parent row in table A. The first user
then saves his dataset which means the row in table A is updated and the row
in table B is added. Lets say that the value of the Id column in table B is
10 (and ofcourse the referring column in table A has the same value). Then
the second user tries to save his dataset to the DB. His Id column value is
15. Since both users have modified the same row in table A there is a
concurrency. Now, the second user wants to "override" this and force his
values into the DB. Therefore the second user refreshes a new dataset from
the DB in which the first user's changes to table A and B are present. Then
this dataset is merged into the second user's dataset with the preserve
changes flag set. But what happens now is that the conflicting row in table
A gets 15 as Id value and in table B we now have two rows (with Id column
values 10 and 15). When the second user then tries to save again everything
works fine. Except for the one thing that the row with Id column value 10 in
table B is "left on it's own" without any reference. If the DB would have
had proper constraints and not only the dataset this would not have
happened, but now it does. Question is, how can I prevent this from
happening?
Thank you for helping out.
//David.
"Val Mazur (MVP)" <group51a@hotmail.com> skrev i meddelandet
news:%2397vvDEUFHA.2172@tk2msftngp13.phx.gbl...
> As I understand you need to know how to work with the identity values when
> they are updated in a database. Is it right? If yes, then example shows
[quoted text clipped - 122 lines]
>>>> Regards,
>>>> David.
Val Mazur \(MVP\) - 06 May 2005 02:10 GMT
Hi David,
I see. What you could do is to define your own stored procedure for
UpdateCommand of the dataadapter. Since you do not have to specify just an
UPDATE SQL statement, you could use SP to use more complex logic. Inside of
SP check if this column already has value, not NULL. If yes, then return
this value as a result of the SP and update column value on a client side
with returned result. If it is NULL in a database, then generate new id and
return new id. This is a general idea, but I am pretty sure it will work.

Signature
Val Mazur
Microsoft MVP
http://xport.mvps.org
> Well, you're right about it has to do with indentity values, but the
> example does not solve my problem (or atleast I don't see it do so). I'll
[quoted text clipped - 159 lines]
>>>>> Regards,
>>>>> David.