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

Dataset.Merge - troubles

I'm trying to load an xml file into a dataset, then load the same xml
file with a slight change into a second dataset, then do a merge to
see what changed between datasets.
DataSet xmlDataSet = new DataSet("Original");
xmlDataSet.ReadXml("C:\\temp\\a.xml");
xmlDataSet.AcceptChanges();
PrintValues(xmlDataSet, "Original");

DataSet xml2 = new DataSet("New");
xml2.ReadXml("C:\\temp\\b.xml");
xml2.AcceptChanges();
PrintValues(xml2, "New");

xmlDataSet.Merge(xml2);

DataSet DSChanges = new DataSet("change");;
DSChanges = xmlDataSet.GetChanges();

DSChanges.AcceptChanges();
PrintValues(DSChanges, "Changes");

public static void PrintValues(DataSet ds, string label)
{
Console.WriteLine("\n" + label);
foreach(DataTable t in ds.Tables)
{
Console.WriteLine("TableName: " +
t.TableName);
foreach(DataRow r in t.Rows)
{
foreach(DataColumn c in t.Columns)
{

Console.Write("\t " + r[c] );
}
Console.WriteLine();
}
}
}

XML file A:
<?xml version="1.0"?>
<sheet title="mytitle">
<section title="General"></section>
<section title="Processor"></section>
</sheet>

XML file B:
<?xml version="1.0"?>
<sheet title="mytitle">
<section title="General1"></section>
<section title="Processor"></section>
</sheet>
I'm doing an Acceptchanges after reading both files to change the row
state to unchanged instead of added. Because if I didn't when I do
the merge, all rows would be Added. I just want to pull the
changes. Pretty much comparing the two datasets and getting the
differences.

Thanks for your help.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 21 '05 #1
1 1631
Hi Scott,

As far as I know. To do a merge in a dataset where the datarows of the
tablew will be merged, the rows needs to have a primary key.

And there may be now rows with the same key in one of the two tables.

It does not know what rows should stay. When you want to do such a kind of
merge, you can create a looping routine which tells which rows have to be
where (when you do that look for the importrow method, because that saves a
lot of work).

http://msdn.microsoft.com/library/de...rtrowtopic.asp

I hope this helps?

Cor
Jul 21 '05 #2

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

Similar topics

8
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
3
by: Li Weng | last post by:
Hi, I have an original dataset. It is copied to 2 different forms. Each form adds a new row to the same table in that dataset. When I merge these 2 dataset back to original one, the 2 new rows...
1
by: ScottDizzy | last post by:
I'm trying to load an xml file into a dataset, then load the same xml file with a slight change into a second dataset, then do a merge to see what changed between datasets. DataSet xmlDataSet...
2
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge(...
4
by: Al | last post by:
I have this scenario: 1. XML file with schema and data is created from SQL Server tables. XML file contains 6 tables, some of them have rows, some of them are empty. 2. XML file is given to the...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
5
by: Mark Chambers | last post by:
Hi there, Can anyone explain the following (very) simple scenario. 1) I make an exact copy of my "DataSet" and delete one record from a given table (in the copy) 2) I invoke...
2
by: Neil Chambers | last post by:
I am trying to get my head around dataset merging but despite a little research I could still use a pointer (or ten). Basically I want to perform an outer join operation on a dataset (created from...
1
by: joproulx | last post by:
Hello all, Here is my problem: I am trying to merge 2 datasets but I don't want to overwrite rows that are already modified in my working dataset. Example: I have one Dataset with only one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.