why to use GetChanges of a DataSet???

  • Thread starter Thread starter Daniel Walzenbach
  • Start date Start date
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.
 
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.
 
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
 
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
 
Thank you William,

I was not aware of your first point.

Best regards.
Daniel Walzenbach
 
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.
 
Back
Top