468,136 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

Merging two datasets deletes parent elements, preserves all children


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();

// Create dataSet to store history file

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

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

foreach(DataRow copyRow in reqRows)
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.WriteXml("xmlFile.xml", XmlWriteMode.IgnoreSchema);

Nov 12 '05 #1
0 2642

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Nikhil Prashar | last post: by
2 posts views Thread by Dan Cooper | last post: by
reply views Thread by garethdjames | last post: by
7 posts views Thread by Jon Vaughan | last post: by
1 post views Thread by cesar.guinovart | last post: by
9 posts views Thread by gardnern | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.