DataTable and DataView

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey
I have dataTable let's call it dtMessages, and I have dvUserMessages. I am
doing st like this:
dvUserMessages = dtMessages.defaultView;
dvUserMessages.rowFilter = "User = 'John'";
than, I would like to delete messages over 20, so that user John after
sending 21 message would have his archive cut let's say to 5 last messages.
I figure out sth like this:
if(dvUserMessages.Count > 20)
{
for(int i=0 ; i < 15 ; i++ )
dvUserMessages.Delete(i);
}

That should cut rows in my view, but how to update dataTable now so that
user has now only 5 rows not 20.
Jarod
 
The view modifies the underlying DataTable. It does not contain it's own version of the data. This is why it's called a data VIEW.

By Calling MyDataRowView.Delete() you will effectively be deleting the data row from the underlying DataTable. Actually, you will
have just marked it for deletion, but this is the same behavior as calling DataRow.Delete().

AcceptChanges() on the DataSet or DataTable to actually remove the rows.
 
Back
Top