-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Sanjay_Narang
Message 8 in Discussion

Hi Pradeep and Ravi,

To clarify your doubts, it is important to understand how ADO.NET maintains the 
disconnected nature of dataset. 

Briefly: When you get a dataset, its two versions are maintained.
One is the original one (exactly same as what you get initially, say Copy 1) and the 
other over which your modificationar are done.(say Copy 2). All your methods (remove, 
delete) act on Copy 2 only. 

The two versions are identified with DataRowVersion (Original and Current). 

Then there is another property DataRowState that tells the operation you did on the 
row. So if you did a delete (NOT remove, i'll explain that little later), this 
property is marked as "Deleted". 

So when you say update(), ADO.NET first need to find which all rows changed till now. 
It does that by searching the  rows whose DataRowState is marked as Deleted, Added or 
Modified. After that it uses the copy 1 to locate the row in actual database, uses 
copy 2 to update that row. 

When You say AcceptChanges, the changes are accepted and row state is made unchanged. 
So if you call AcceptChanges  before Update(), nothing will happen to database. 
Pradeep, you are calling it after Update(), although, it won;t do any harm, but it is 
redundant as UPdate() implicitly call AcceptChanges.

It is explained very well at following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontodatasetupdates.asp

Now your answers:
When to use Remove:
Now both Remove and Delete methods are available in DataRowCollection. The Remove 
methods exist to comply for Collection interface and not for data update. When you 
call Remove(), the row is removed from copy 2, and there is no way for ADO.NET to find 
that this operation has been performed (as it relied on DataRowState)

You use Remove typically when you want to see the changes at the client end, but don't 
want that to happen in actual database e.g. you have displayed some records in 
DataGrid, you want users to be able to remove some records and see that in DataGrid, 
but do not want those changes to go to Database. 

So Ravi, i think as per your requirement, you should use Remove(). But in case you 
want to know the DataRowState also, then use Delete only. But call RejectChanges() 
before Update().

Hope that clarifies the doubts.

Cheers
Sanjay



-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to