List Info

Thread: updating child records in a DataSet w/ new autoinc values after parent insert?




updating child records in a DataSet w/ new autoinc values after parent insert?
user name
2006-11-21 21:07:39
I would strongly recommend you not do cascading deletions.
Roy

-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailtoOTNET-WI
NFORMSDISCUSS.DEVELOP.COM] On Behalf Of
Chris Bordeman
Sent: Tuesday, November 21, 2006 2:16 PM
To: DOTNET-WINFORMSDISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] updating child records in a
DataSet w/
new autoinc values after parent insert?

I was actually looking for something more generalized.

I ended up setting cascading updates and deletions on the
relations.
The problem there is that when the parent table is updated
not only does
it update the child records, it also sets their state to
'Modified.'
This is a big problem because their state was initially
'Added.'  So now
when I use the data adapter to update the child table, I get
concurrency
errors saying the record could not be modified.  Of course,
it was never
added to the database!

Any ideas?

-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailtoOTNET-WI
NFORMSDISCUSS.DEVELOP.COM] On Behalf Of
Phil Sayers
Sent: Tuesday, November 21, 2006 10:59 AM
To: DOTNET-WINFORMSDISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] updating child records in a
DataSet w/
new autoinc values after parent insert?

hook into the dataadapter events...
i forget the name. but something like the
"Updated" event is a good
spot.
in there take the new PK value from the parent row, and
update all of
it's child rows with the new value.
now when the dataadapter starts inserting the child rows
they will have
the correct reference to the parent.


-----Original Message-----
From: Discussion forum for developers using Windows Forms to
build apps
and controls [mailtoOTNET-WI
NFORMSDISCUSS.DEVELOP.COM]On Behalf Of
Chris Bordeman
Sent: Tuesday, November 21, 2006 11:43 AM
To: DOTNET-WINFORMSDISCUSS.DEVELOP.COM
Subject: [DOTNET-WINFORMS] updating child records in a
DataSet w/ new
autoinc values after parent insert?


Hi all. Using Dot Net 2.0.

I have a TYPED dataset generated by VS.  It contains a
parent and a
child table with a relationship set up in the MSSQL database
and showing
in the dataset.  BOTH tables have new records that need to
be added to
database.

I'm able to retrieve the server's autoinc values on the
parent table,
but I can't seem to get my data adaper to filter the new
autoinc values
down to the foreign key field in the child table.


HOW EXACTLY IS THIS DONE???



I'm currently doing 3 things:
1.  Added an output parameter to the insert command to grab
the new
autoinc value and feed it into my autoinc field.
2.  Set insertCommand.UpdatedRowSource =
UpdateRowSource.Both (figure
good idea to grab it all).
3.  Appended " SELECT " +
identityColumn.ColumnName + " =
SCOPE_IDENTITY()" to the insert command.

Does #3 keep the entire column's values from being fed back
to the
DataTable row?

Do I need to AcceptChanges?

What about if the operation fails and the transaction is
rolled back,
how do I undo changes made to the dataset?

THANKS!!!

Chris B.
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )