Solved

AutoIncrement With master detail relationship

Posted on 2006-11-15
9
541 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
System.Security 2 27
FTP file download using c# 3 23
How to make a Gridview column hidden (visibility false) in the HTML code? 2 16
C# Gridview 1 32
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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