S
ScottDizzy
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.
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.