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

Compare Datasets

Hi
I'm looking for some help comparing 2 datasets,
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.

I'm fairly new to c# and .net and i'm struggling with this, so any help
would be appreciated.
Thanks in advance
Charlie

Nov 17 '05 #1
2 7552
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
Nov 17 '05 #2
Thats a great help, thanks a lot, I'll work on this later on today, and
post my results.
I had been trying to get somewhere with dataset.merge before i posted
this, but i got the feeling it wasn't capable of doing what i wanted,
so at least i was right about that.
thanks again.
Charlie.

Nov 17 '05 #3

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

Similar topics

2
by: codejockey | last post by:
I have a simple project that requires I take a set of data from an Excel spreadsheet, compare it to a table in SQL Server (where column names match), and if there are changes in the Excel sheet,...
0
by: codejockey | last post by:
Please forgive the repost, but I'm trying to avoid the hack I want to implement since I cant get this sample to work. Can anyone help? *********************** William: Thanks for the reply. I...
1
by: Mark | last post by:
by m.r.davies I have 2 tables on seperate Db's (and servers) I want to use a datareader on the first table to pick the booking ref, and then use that booking ref to query the 2nd DB when i have...
4
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB...
0
by: Frank | last post by:
Hello, Developing an app where the user fills out a sometimes quite lengthy form of chkboxes, txtboxes, radbtns, etc. User responses are saved to a mySql db, which the user can later edit. When...
0
by: austenr | last post by:
I need to compare data sets that have been updated with newer versions. Is there a way to compare the old data set to the new one and determine what tables differ? The environment is DB2. Thanks...
6
by: Al | last post by:
I'd like to know if there were any changes in the DataSet which was populated by reading XML file. 6 DataTables with data or just structure with no data inside of it. I think about this scenario:...
3
by: sonymathur | last post by:
I'm using two datasets DS1 & DS2 (both hold data with same schema) in VB.Net 1.1 DS1 is main datasets and DS2 is like subset to DS1.Now how should i remove datarows from DS1 that are like in DS2....
12
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.