Hi,
"Chris Bordeman"
I'm too lazy now to work up an example project but here are some posts by
people having the same problem:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=928845&SiteID=1
Here's how to reproduce:
Create a dataset, add 2 tables and a relationship with cascading updates
between the two and add some new rows to both tables. All rows will have
a RowStatus of 'Added'.
Use a dataadapter to update the parent table, with
AcceptChangesDuringUpdate set to false.
The DataAdapter will obviously use your InsertCommand foreach Added row, but
it does it like this:
-> RowState.Added
1) setup command/set parameter values ...etc...
2) execute InsertCommand
3) if the InsertCommand.UpdatedRowSource = FirstReturnedRecord
(which is quite normal if you use autonumber keys), then it will _always_
call AcceptChanges
-> RowState.Unmodified
4) load the values from FirstReturnedRecord into the DataRow
(this will set the new pk)
-> RowState.Modified
5) if AcceptChangesDuringUpdate = true, call AcceptChanges again
-> RowState.Unmodified
So, if you use an InsertCommand which retrieves the autonumber key, then
turning off AcceptChangesDuringUpdate will make the RowState go from Added
to Modified.
And if the ForeignKeyConstraint has AcceptRejectRule=Cascade then a similar
thing will happen for the related child rows: when AcceptChanges is called
on the parent row (3) it will cascade and call AcceptChanges on the child
row, changing its state to unmodifed, then when the new key is retrieved (4)
it will propagate the key to the child row (UpdateRule=Cascade), making the
child row enter a modified state.
Offcourse i don't know whether you are using AcceptRejectRule=Cascade but if
you are you should probely not, there are very few situations where this is
wanted.
HTH,
Greetings