473,396 Members | 2,026 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,396 software developers and data experts.

How to get the differences between two DataSets in a thrid one?

Hi there

I have two typed DataSets. One represents the state of a certain DB
table some time ago, the other represents the current state of the
same DB table. Now I would like to get the changes in a third table,
each row with the appropriate row state Added, Deleted or Modified. Is
there any way to do that with .NET (except for hand-crafting the
comparison myself)?

I have tried to get the changes with setting
SqlDataAdapter.AcceptChangesDuringFill to false and then filling the
old data set. But this sets *all* rows to Modified, even if there was
no change at all!

I need this functionality because I only want to send the data that
has actually changed to the clients (transmitting the full DataSet is
not an option because it can very well be 60MB+ in size and network
bandwith is precious).

Any help is greatly appreciated.

Thanks,

Andreas
Nov 15 '05 #1
3 5247
Andreas,

Have the changes occured on the back end database, or have the changes
occured in the dataset (you manually added rows, etc, etc). If the case is
the latter, then you can call the GetChanges method on the DataSet and it
will give you a new DataSet with only the changes since the last time
AcceptChanges has been called on the dataset.

If the case is the former, then you will have to query the back end.
You have a list of unique ids that were in the table, so if you select out
the records from the table where the id is not in that set, those are the
adds. Then, you have to perform a select where the ids in that set are not
in the table. These are the deletes. Finally, you will have to do a
comparison (either field by field, or by a timestamp of some sort) for the
rows that still exist in the table (these are edits).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Andreas Huber" <ah****@gmx.net> wrote in message
news:3e**************************@posting.google.c om...
Hi there

I have two typed DataSets. One represents the state of a certain DB
table some time ago, the other represents the current state of the
same DB table. Now I would like to get the changes in a third table,
each row with the appropriate row state Added, Deleted or Modified. Is
there any way to do that with .NET (except for hand-crafting the
comparison myself)?

I have tried to get the changes with setting
SqlDataAdapter.AcceptChangesDuringFill to false and then filling the
old data set. But this sets *all* rows to Modified, even if there was
no change at all!

I need this functionality because I only want to send the data that
has actually changed to the clients (transmitting the full DataSet is
not an option because it can very well be 60MB+ in size and network
bandwith is precious).

Any help is greatly appreciated.

Thanks,

Andreas

Nov 15 '05 #2
You can get changes made to a dataset with

DataSet dsChanges = dsChangedDataSet.GetChanges();

This returns only the rows that has changed.

If you use AcceptChanges you tell the dataset that you want to save the
changes and discard changedata. Which is something you want to do after
you update a database.

However, if you have two datasets with no changedata and you want to find
out what has changed by comparing the two ... I have no idea. Sounds like
hard work. Something involving foreach(DataRow in dsChangedDataSet.Rows).

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3
Nicholas Paldino [.NET/C# MVP] wrote:
Andreas,

Have the changes occured on the back end database, or have the
changes occured in the dataset (you manually added rows, etc, etc). [snip]

They have occured in the database. There is one server with DB and an
arbitrary number of (remote) clients. Clients can read from a given DB
table, modify the returned data set and send the changes back to the server,
which will write them back to the database. So far there is no problem, as
this can nicely be done with DataSet.GetChanges().
However, changes made with client A must also be visible on client B as soon
as possible. It's no problem to detect that a particular DB table has
changed, but it's not at all clear which (if any) of the rows that are
currently displayed on B have changed (A might have displayed a differently
sized page of rows). That's why I asked my original question.
If the case is the former, then you will have to query the back
end. You have a list of unique ids that were in the table, so if you
select out the records from the table where the id is not in that
set, those are the adds. Then, you have to perform a select where
the ids in that set are not in the table. These are the deletes.
Finally, you will have to do a comparison (either field by field, or
by a timestamp of some sort) for the rows that still exist in the
table (these are edits).


Hmmm, I would have guessed that I'm far from being the only one with this
problem. It's a bit disapointing to hear that I have to implement what
presumably a lot of people have written before :-(, but thanks anyway.

Regards,

Andreas
Nov 15 '05 #4

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

Similar topics

2
by: beyond | last post by:
i need a sql-statement for this problem i ve got a table like this ID;value 1;30 2;34 3;44 the result of sql-statement should calculate differences to previous/other datasets like this
4
by: Alpha | last post by:
I have a small Window application and through out the different forms I create a different dataset. At the begining I used the Tools to drag and drop the SqlDataAdapter, connection and dataset...
1
by: Rui Wang via .NET 247 | last post by:
Hi all, I am coding a web serivce and VS.net2003 is the tool I am using. I am constantly getting errors back from the thrid party web serivce, which I am connecting to. Can anyone suggest a good...
9
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
16
by: Luqman | last post by:
Is it recommended to use datasets in ASP.Net 2.0 / VS.Net 2005 ? Best Regards, Luqman
4
by: rdemyan via AccessMonster.com | last post by:
I have to import building information from another system. I've decided to keep track of each set of data downloaded by including a Download_Date. That way I keep historical data. My table has...
4
by: Ronald S. Cook | last post by:
I've always used untyped datasets. In a Microsoft course, it walks through creating typed datasets and harps on the benefits. It has you drag all these things around ..wizard, wizard, wizard......
25
by: Penelope Dramas | last post by:
Hello, I'm in a front of very serious .net redesign/rewrite of an old VB6 application. I had been asked to make it .NET 2.0 and would like to ask couple of questions regarding data access as...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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...

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.