gi*****@gmail.com wrote:
each dataset has 2 datatables; the first table's rows consist of
text, status (1 or 0), GUID
The GUID and the text will always be in sync in each version of the
dataset, but the status could be different. The second table in each
dataset contains a list of GUID's that have been deleted.
What I want to do is match each GUID and check if the status in either
version of the table has changed to 1, if so use this value in the
merged dataset, then check if either dataset has a new rows (based on
GUID) and add them to the merged dataset, and finally check both the
removed GUIDs lists and remove any rows that have these GUIDS in the
merged datatable.
Unfortunately, I don't think DataSet.Merge() is flexible enough to support
the behaviour you desire. If these tables were in a real database, you
could achieve something like this with an outer join followed by a DELETE
statement. As it is, however, you can still use the primary-key foreign-key
relationship functionality to speed things up significantly.
First, create a DataSet bothSet and copy all four tables into it. Let's say
your tables are called T1 and T2 (each with text, status, GUID) and D1 and
D2 (the deleted row tables). Consider this statement:
bothSet.Relations.Add(
new DataRelation("T1_to_T2_GUID",
bothSet.Tables["T1"].Columns["GUID"],
bothSet.Tables["T2"].Columns["GUID"],
false));
After doing this, you can iterate through T1 and use the DataRow member
GetChildRows to identify any rows in T2 with the same GUID. You can examine
both and make your decision about what row to insert into your result
table. You can also identify new rows as the rows which have no child rows.
If you add the same relation with T1 and T2 reversed, you can use it to
identify new rows in T2 as well.
Finally, to perform the necessary deletions, you can play the same trick.
Create a relation between D1/D2 and your result table based on the GUID as
above. Then iterate through D1 and D2 and use GetChildRows to get the rows
you need to delete (with DataRow's Delete member).
Caveat: I have not compiled or tested any code in this mail. If anyone can
come up with a better way of doing this I invite it. I hope this helps, and
please write back if any of this wasn't clear or was unhelpful.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included code samples are subject to the terms
specified at
http://www.microsoft.com/info/cpyright.htm