• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

AutoIncrement With master detail relationship

I Have a Master Detail relationship where the Parent PK is an AutoIncrement field.

I am using a ADO 2.0 Dataset and i set the DataColumn's AutoIncrement and seed settings to -1, -1 so each new row gets added with a fake negative ID.

I then add a new Parent row and it gets an ID of -1, I then add Child row(s) and set the parent Id to -1.

I then attempt to save by calling the the dataAdapter.update  (first on the parent and then on the child).

the parent row gets the new ID (the SQL command refershes the Data correctly) and the child row is even updated with the correct parent Id that was generated by the SQL server.

the problems now begin....

If i set the adapter.AcceptChangesDuringUpdate = true (before saving the parent table).

I call the adapter.update for the child table and It does not see any updated rows in the child table.

If i set the adapter.AcceptChangesDuringUpdate = false (before saving the parent table).

I call the adapter.update for the child table and it runs the Update command instead of the Insert command.

It seems the Update of the parent is changing the RowState of the child (the parentID is updated in the child row by the adapter), however since the child rowstate is added, any update to it should not change it's row state. (this row was never saved to the database, so any updates prior to the save it should remain in state added).

0
ANAT2403
Asked:
ANAT2403
  • 4
  • 3
1 Solution
 
Gautham JanardhanCommented:
<adapter.AcceptChangesDuringUpdate = true >

without doing this cant u try AcceptChanges() method

after both the updates
0
 
ANAT2403Author Commented:
The first update (parent table) messes up the rowstate of the child table, once that happened i lost the rowstate info in the child rows.
0
 
Gautham JanardhanCommented:
adapter.AcceptChangesDuringUpdate = false

master.update();
child.update();
master.AcceptChanges();
Child.AcceprtCahnges();
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ANAT2403Author Commented:
That is what i do but....

If i set the adapter.AcceptChangesDuringUpdate = false (before saving the parent table).

I call the adapter.update for the child table and it runs the Update command instead of the Insert command.

It seems the Update of the parent is changing the RowState of the child (the parentID is updated in the child row by the adapter), however since the child rowstate is added, any update to it should not change it's row state. (this row was never saved to the database, so any updates prior to the save it should remain in state
0
 
Gautham JanardhanCommented:
are u sure the row state is (Modified) not added
0
 
Gautham JanardhanCommented:
how did u come to this conclusion did u put a break point and saw the child row's row-state

if that is the case one more query how are u populationg data is it by user entry or some other way


one more thing can u put a break point before calling the update of the parent and see waht the row state is
0
 
ANAT2403Author Commented:
Here is the solution, there are a few Microsoft features to workaround.

http://support.microsoft.com/kb/320301


1)Create a new DataAdapter based on the original one to prevent the
   CommandBuilder from modifying the SQL statements,
   specifically the custom InsertCommand.
   You do not need this if you roll your own commands and parameters
   or if you use the Visual Tools to do it.



2)Use a delegate to prevent AcceptChanges from occurring on Deletes and Inserts.
   This is for a limitation of the DataAdapter; see Q313540.
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now