Solved

AutoIncrement With master detail relationship

Posted on 2006-11-15
9
532 Views
Last Modified: 2008-01-09
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
Comment
Question by:ANAT2403
  • 4
  • 3
9 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17955860
<adapter.AcceptChangesDuringUpdate = true >

without doing this cant u try AcceptChanges() method

after both the updates
0
 

Author Comment

by:ANAT2403
ID: 17956300
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17956515
adapter.AcceptChangesDuringUpdate = false

master.update();
child.update();
master.AcceptChanges();
Child.AcceprtCahnges();
0
 

Author Comment

by:ANAT2403
ID: 17959768
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17962889
are u sure the row state is (Modified) not added
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17962899
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
 

Author Comment

by:ANAT2403
ID: 17974456
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18171221
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now