473,722 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7569
gi*****@gmail.c om 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.Relatio ns.Add(
new DataRelation("T 1_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
9957
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, update the SQL Server table with said changes. The datasets are about 2000 rows. My thinking is performing a check row by row is inefficient, so I thought about how I could compare the two as datasets and resolve differences. The SQL Server table...
0
1579
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 havent been able to get the sample to work. I notice the cursor cycling through the Excel records, but the SQL table always shows up empty. Notice anything wrong here?
1
1883
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 the correct row in the 2nd DB I want to compare each field in the 2 tables to see if they match Every time i try and think how i end up with a while loop for the reader on table1 and a while loop for the reader on table 2 any ideas how i'm going...
4
1992
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 contains the same items but not necessarily all the items. I need to know which items are missing. I remember messing with a compare array function but now I can't seem to find it anywhere. Ideas? I would rather NOT loop through each item in...
0
1186
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 the user chooses to edit, I pull the responses from the db, toss them in a dataset, check the checks, fill the txtboxes, etc.,etc. The user then adds, deletes, or changes entries as needed and clicks the Save Changes button. Here is where the fun...
0
1726
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 for your help.
6
1846
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: I create 2 datasets and populate both from the same XML file. Then the first one is used as DataSource for many controls and the second one is untouched. If there were some changes in the first one, I'd like to know it and would like to compare...
3
2167
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. Thanks In Advance. Sonymathur.
12
3601
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 gridview, for example, I loop through a datareader, populating an array list with instances of a custom class in the middle tier, and then send the array list up to the presentation layer and bind the gridview to it. If I use a typed dataset, I...
0
8740
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9239
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9158
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4503
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.