why to use GetChanges of a DataSet???

D

Daniel Walzenbach

Hi,



I have seen a lot of code using .GetChanges of a System.Data.DataSet like the following:



myDataSetWithChanges = myDataSet.GetChanges

myDataAdapter.Update(myDataSetWithChanges)



Does this approach make any sense? I mean that Update of the DataAdapter has to iterate through all items in a DataTable so why creating a new object and wasting resources if the same con be done without? Can anybody explain this subject to me?



Thank you in advance.

Best regards


Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.
 
W

William Ryan

Two things come to mind. Take for example a Web Service that is used to
submit your changes to the database. Let's say it has 3 changed rows and
there are 1000 total. If you use GetChanges and send that dataset you'll
send a Ds with 3 rows in it as opposed to one with 1000 rows. Depending on
the size of the dataset, performance could be greatly enhanced by using
GetChanges. The other thing that comes to mind is Merging datasets. In a
disconnected scenario, one which uses TimeStamps for instance to check the
state of rows, once again using a Web Service. In order to keep all of your
data snyced, particluarly in cases where you are using AutoIncrement values
or two clients are updating different parts of a record simultaneously...you
can use Merge to sync these up.

In a nutshell, GetChanges allows you to pass and work with only the data
that has been changed and not wasting resources with the rest.

HTH,

Bill
message Hi,



I have seen a lot of code using .GetChanges of a System.Data.DataSet like
the following:



myDataSetWithChanges = myDataSet.GetChanges

myDataAdapter.Update(myDataSetWithChanges)



Does this approach make any sense? I mean that Update of the DataAdapter has
to iterate through all items in a DataTable so why creating a new object and
wasting resources if the same con be done without? Can anybody explain this
subject to me?



Thank you in advance.

Best regards


Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email
address.
 
D

Daniel Walzenbach

William,



Thank you for your quick answer. I can only confirm what you said and it makes sense in the scenario you described. But what sense does it make if I have a "direct" connection to a SQL Server (or what ever the database might be) though a DataAdapter which executes a sp or SQL statement? I have seen this scenario much too often for to ask myself if I have overlooked sth.



Best regards

Daniel Walzenbach
 
W

William Ryan

The functionality associate with merge. For isntance, if you get a
Concurrency exception you cna use GetChanges with Merge to recover...
http://msdn.microsoft.com/library/d...on/html/vbwlkhandlingconcurrencyexception.asp

Another thing you can use it for is in instances where you may be
temporarily unable to connect to your database. In many wireless/PDA
scenarios, this is not uncommon. So if you can't connect for a period of
time, you can write your data to XML and use the GetChanges with Merge to
sync everything up once you can connect again...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndive/html/data12132001.asp

Another thing you can do is use GetChanges with DataRowState so that you can
only work with Insert/Deletes etc one at a time.

HTH,

Bill
message William,



Thank you for your quick answer. I can only confirm what you said and it
makes sense in the scenario you described. But what sense does it make if I
have a "direct" connection to a SQL Server (or what ever the database might
be) though a DataAdapter which executes a sp or SQL statement? I have seen
this scenario much too often for to ask myself if I have overlooked sth.



Best regards

Daniel Walzenbach
 
D

Daniel Walzenbach

Thank you William,

I was not aware of your first point.

Best regards.
Daniel Walzenbach
 
G

Greg

Yes, it greatly reduces bandwidth.
Hi,



I have seen a lot of code using .GetChanges of a System.Data.DataSet like the following:



myDataSetWithChanges = myDataSet.GetChanges

myDataAdapter.Update(myDataSetWithChanges)



Does this approach make any sense? I mean that Update of the DataAdapter has to iterate through all items in a DataTable so why creating a new object and wasting resources if the same con be done without? Can anybody explain this subject to me?



Thank you in advance.

Best regards


Daniel Walzenbach

P.S. If you need to contact me simply remove ".NOSPAM" from my email address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top