473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Saving Parent-Child when Identity Column is Involved

Since I can't get answer from the author, can someone address this?

In this article . . .
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

In the "The Transaction and Sequence" paragraph, the author makes this
statement:

"The row is left with different original and current values so that when I
merge the delta DataSet with the originating DataSet, they will sync with
each other properly, using the original values of the OrderID DataColumns. "

Since the author is talking about the insertion of "new" orders where the
Order_ID column is an identity column along with the associated detail
records, the orginal dataset has only current values -- there are no original
values. Added records are merged on the basis of current values.

Here is the code:
DataSet oDsDelta = oOrder.SaveData(oDs.GetChanges());
oOrder = null;
oDs.EnforceConstraints = false;
oDs.Merge(oDsDelta.Tables["Orders"]);
oDs.Merge(oDsDelta.Tables["OrderDetails"]);
oDs.AcceptChanges();
oDs.EnforceConstraints = true;

What is too long to post here is the code that takes oDsDelta and ensures
that its rows have an Original Order_ID value equal to the psuedo key value
assigned by the original dataset and a Current Order_ID value equal to the
database's value. So you can assume the that oDsDeleta has an Original value
and Current value. So a given row in oDs might have -1 as the Current value
but no Original value. The corresponding row in the oDsDelta with have
498576 as the Current Value and -1 as the Original value.

Based on this there is no way to merge these rows. Plus, I believe the rows
have differ row states at this point. What am I missing???

This article has the potential to be very helpful if it only works or if I
can understand it correctly.
Nov 19 '05 #1
1 1370
Here is the result of using the technique of the article. It works, but I
cannot explain how. Looking at the Original Dataset and the Changes Datatset
their original values do not match nor do their current values. The only
explanation I can come up with is the dataset tries more than one matching
scheme. If match on orginal values fails, try current values. If match on
current values fails, try matching original value to current value. If match
found, merge rows else add row.

-----------------------

BEFORE MERGE - Original DataSet
dsOption
---------------------------
tblGroup
Original: Added
Current: -2 -- Tone -- Added
---------------------------
tblOptionGroup
Original: Added
Current: -2 -- BW -- Black & White -- Added
Original: Added
Current: -2 -- CZ -- Colorize -- Added
Original: Added
Current: -2 -- SEP -- Sepia -- Added

BEFORE MERGE - dsChanges
dsChanges
---------------------------
tblGroup
Original: -2 -- Tone -- Modified
Current: 20 -- Tone -- Modified
---------------------------
tblOptionGroup
Original: -2 -- BW -- Black & White -- Modified
Current: 20 -- BW -- Black & White -- Modified
Original: -2 -- CZ -- Colorize -- Modified
Current: 20 -- CZ -- Colorize -- Modified
Original: -2 -- SEP -- Sepia -- Modified
Current: 20 -- SEP -- Sepia -- Modified

AFTER MERGE - Before Accept Changes - Original Dataset
dsOption
---------------------------
tblGroup
Original: -2 -- Tone -- Modified
Current: 20 -- Tone -- Modified
---------------------------
tblOptionGroup
Original: -2 -- BW -- Black & White -- Modified
Current: 20 -- BW -- Black & White -- Modified
Original: -2 -- CZ -- Colorize -- Modified
Current: 20 -- CZ -- Colorize -- Modified
Original: -2 -- SEP -- Sepia -- Modified
Current: 20 -- SEP -- Sepia -- Modified

AFTER MERGE - After Accept Changes - Original Dataset
dsOption
---------------------------
tblGroup
Original: 20 -- Tone -- Unchanged
Current: 20 -- Tone -- Unchanged
---------------------------
tblOptionGroup
Original: 20 -- BW -- Black & White -- Unchanged
Current: 20 -- BW -- Black & White -- Unchanged
Original: 20 -- CZ -- Colorize -- Unchanged
Current: 20 -- CZ -- Colorize -- Unchanged
Original: 20 -- SEP -- Sepia -- Unchanged
Current: 20 -- SEP -- Sepia -- Unchanged
"WhiskyRomeo" wrote:
Since I can't get answer from the author, can someone address this?

In this article . . .
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

In the "The Transaction and Sequence" paragraph, the author makes this
statement:

"The row is left with different original and current values so that when I
merge the delta DataSet with the originating DataSet, they will sync with
each other properly, using the original values of the OrderID DataColumns. "

Since the author is talking about the insertion of "new" orders where the
Order_ID column is an identity column along with the associated detail
records, the orginal dataset has only current values -- there are no original
values. Added records are merged on the basis of current values.

Here is the code:
DataSet oDsDelta = oOrder.SaveData(oDs.GetChanges());
oOrder = null;
oDs.EnforceConstraints = false;
oDs.Merge(oDsDelta.Tables["Orders"]);
oDs.Merge(oDsDelta.Tables["OrderDetails"]);
oDs.AcceptChanges();
oDs.EnforceConstraints = true;

What is too long to post here is the code that takes oDsDelta and ensures
that its rows have an Original Order_ID value equal to the psuedo key value
assigned by the original dataset and a Current Order_ID value equal to the
database's value. So you can assume the that oDsDeleta has an Original value
and Current value. So a given row in oDs might have -1 as the Current value
but no Original value. The corresponding row in the oDsDelta with have
498576 as the Current Value and -1 as the Original value.

Based on this there is no way to merge these rows. Plus, I believe the rows
have differ row states at this point. What am I missing???

This article has the potential to be very helpful if it only works or if I
can understand it correctly.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
10
by: Geoff Cox | last post by:
Hello, I have a series of pages each of which creates an array of values. How do I keep all the array values until the last page? Cheers Geoff
14
by: Amitabh Deepak | last post by:
Is there any way to check whether daylight saving is enabled on a linux machine?
3
by: Martin Arvidsson | last post by:
Hi! Got a question, don't know if it's the right forum, but i will give it a try. I am building a CRM system for a customer, who has special needs. On a task i want to be able to bind...
1
by: darrel | last post by:
I have a function that uploads a file to a specific directory, making the directory if it doesn't already exist. This works, unless I try to upload a file to a pre-existing directory. If I do...
1
by: eljainc | last post by:
Hi I'm looking for general code examples to save a form or the components of a form for later retrieval. For example, lets say at runtime some controls (listview, panel, labels) were placed onto...
1
by: amu | last post by:
Would you please help me because i am trying to save using oracle but i am coding with VB.net and my forms are designed using A.S.P.net. the error is ORA-02291: integrity constraint...
14
by: Stodge | last post by:
I'm trying to do the following. I have a Python application that is run: python app1.py --location=c:\test1 What I want to do is save the location parameter, so I can then do (in the same...
9
by: Wingot | last post by:
Hey, I am using Visual Studio 2008 Beta 2 for some application development in C#, but I presume that the following question applies equally well to any environment.
27
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.