472,804 Members | 1,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 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 2831

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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.