-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Sitaraman
Message 9 in Discussion
Hi And I thought i understood the difference btwn DataRowCollection.Remove() and
DataRow.Delete()!!!!! Sanjay's explanation that "The Remove methods exist to comply
for Collection interface and not for data update" was quite logical and i was
convinced. But i took a chance and decompiled the DataRowCollection.Remove and
DataRow.Delete methods and this is wat i got DataRow.Delete() : public void
Delete()
{ if (this.inDeletingEvent)
{
throw ExceptionBuilder.DeleteInRowDeleting();
}
if (this.newRecord == -1)
{
return;}
this.Table.DeleteRow(this);
} DataRowCollection.Remove() : public void Remove(DataRow row)
{ if (!this.list.Contains(row))
{
throw ExceptionBuilder.RowOutOfRange();
}
if ((row.RowState != 8) && (row.RowState != 1))
{
row.Delete();
if (row.RowState != 1)
{
row.AcceptChanges();
}
}
} Here note that DataRowCollection.Remove() itself, in turn calls
DataRow.Delete() which means that Remove() should work like a superset of Delete(),
that is Remove = Delete + something else(in our case, as the code shows- +
AcceptChanges() ). If that is the case, if delete() deletes the row from the
underlying physical table, then logically remove() also should work in the same
way(coz, it calls delete() internally). Isnt it??? But as we have noted Remove
surprisingly leaves the underlying table unaffected. Tried out a sample code and my
observation is as follows. The culprit here is AcceptChanges. We all know that
whenever AcceptChanges is called, the RowState is set to "UnChanged". What is really
happenning is that, When we call Row.Delete() in our code The Initial
RowState of the Row is "UnChanged" DataRow.Delete is called The RowState is
set to "Deleted" This continues for multiple records Update is called
Each and every row is traversed If a row's rowstate is "Deleted"(to be
precise RowState is NOT "Unchanged", as it can be "Modified" or "Added" also) then
that is reflected in the underlying table
Given this understanding, lets see wat happens if we call AcceptChanges. The
Initial RowState of the Row is "UnChanged" DataRow.Delete is called The
RowState is set to "Deleted" AcceptChanges is called The RowState of
the Row is reset to "UnChanged" again This continues for multiple records Update
is called Each and every row is traversed Due to AcceptChanges called
in Step 4, all the rows will contain the Rowstate as "Unchanged". Therefore,
the underlying table is NOT updated Going back to the decompiled code, Note that
DataRowCollection.Remove calls the DataRow.Delete() and then
AcceptChanges(). While the DataRow.Delete would have deleted the row and set the
RowState of the Row to "Deleted", the subsequent call to the AcceptChanges would have
reset it to "Unchanged". SO when the update is called it will not find any rows whose
RowState is "Added"/"Modified"/"Deleted". SO the underlying table is not updated
This is probably deleberate from Microsoft, so as to provide a delete()
method which will delete from the dataset and also the underlying table and to
provide a remove() method, which will comply to the collection.remove mechanism , but
will not update the underlying table[achieved by calling AcceptChanges() after calling
DataRow.Delete() inside DataRowCollection.Remove()]. Hope this clarifies our doubts
between remove() and delete() regards, sr
-----------------------------------------------------------
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]