473,378 Members | 1,531 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,378 software developers and data experts.

Merging two datasets deletes parent elements, preserves all children

Hi,

My problem: Merging two datasets deletes parent elements, preserves
all children.

I've created two dataSets. Each use the same schema, parent-child
nested tables.

The first dataSet is loaded with historical data read from an XML
file. The second dataSet has current data filled from a dataGrid.
The system takes selected dataGrid data, dataSet updates a child
element value, merges with the first dataSet, and finally writes out
the latest version of the history file.

Inside the file, there is a mix of parent table elements and children.
All the children are preserved and correct, but are assigned to a
subset of parent elements. Most often only two parent elements, the
first two, are created. The children of the first and second parent
elements are properly assigned. But the rest of the children are
assigned to either parent element in a repeatable pattern depending on
which row of the dataGrid is selected. Using AcceptChanges creates a
single parent element that holds all the children.

Thanks in advance.

My environment: .NET, framework 1.1, C#, windows forms, VS 2003.
// Create dataSet to store dataGrid data

dsNew = null;
dsNew = new DataSet();
dsNew.ReadXmlSchema("xmlFile.xsd");

// Create dataSet to store history file

dsHistory = null;
dsHistory = new DataSet();
dsHistory.ReadXmlSchema("xmlFile.xsd");
dsHistory.ReadXml("xmlFile.xml");
// Populate Parent table from dataGrid dataSet
DataTable dayNew = dsNew.Tables["Day"];

foreach(DataRow copyRow in dayRows)
dayNew.ImportRow(copyRow);
// Populate Child table from dataGrid dataSet
DataTable reqNew = dsNew.Tables["Request"];

foreach(DataRow copyRow in reqRows)
reqNew.ImportRow(copyRow);
//
DataRow daRow;

// Loop through update rows based on
// number of children rows selected in datagrid

for(int i = rowCount - 1; this.threshold - 1 < i; i--)
{
// assign the row
daRow = dsNew.Tables["Request"].Rows[i];
// Set the "Accept" column false
daRow[2] = false;
}

// Merge the historical and new dataGrid dataSet

dsNew.Merge(this.dsHistory);

dsNew.WriteXml("xmlFile.xml", XmlWriteMode.IgnoreSchema);

dsNew.Clear();
dsNew.Dispose();
dsHistory.Clear();
dsHistory.Dispose();
Nov 12 '05 #1
0 2859

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

Similar topics

0
by: Natehop | last post by:
I've been attempting to design an n-tiered framework leveraging .NET's strongly typed Dataset. My Framework will serve as the foundation to several client apps from Windows applications to web...
4
by: feanor | last post by:
I need to select children checkboxes when selecting the parent one. This is my function: function SelectChildrens(checkbox_name){ form = document.forms; Sname = checkbox_name.split("-"); for...
0
by: Walt Borders | last post by:
Hi, My problem: Merging two datasets deletes parent elements, preserves all children. I've created two dataSets. Each use the same schema, parent-child nested tables. The first dataSet is...
2
by: Nikhil Prashar | last post by:
I'm trying to merge two XML files that have the same structure but not necessarily the same nodes in the same order. I've tried opening the files as datasets and using the DataSet.Merge() function,...
2
by: Dan Cooper | last post by:
I've got two datasets, each containing a single data table. dstDataSetA.Tables("TableA") dstDataSetB.Tables("TableB") I want to merge them together and delete any non-matching rows. ...
0
by: garethdjames | last post by:
For scalability we wish to use disconnected DataSets and hold them in the application cache. This means that multiple concurrent users will be reading the data (its read only) The DataSet is...
7
by: Jon Vaughan | last post by:
I have 2 datasets , one returned as a dataset from a webservice and one created client side form the same stored procedure that is returned from the webservice. I then try and merge the data, but...
1
by: cesar.guinovart | last post by:
I have the following table CREATE TABLE ( int IDENTITY(1,1) CONSTRAINT PK_tbl_Items__item_id PRIMARY KEY, int DEFAULT(NULL) CONSTRAINT FK_tbl_Items__item_id__parent_id REFERENCES ( ...
9
by: gardnern | last post by:
We have X number of data sets, of Y length each. For example... Small, Medium, Large and Red, Green, Blue, Yellow We need to generate a list of all possibilities Small Red
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.