DataTable and DataView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jarod

    DataTable and DataView

    Hey
    I have dataTable let's call it dtMessages, and I have dvUserMessages. I am
    doing st like this:
    dvUserMessages = dtMessages.defa ultView;
    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(dvUserMessag es.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
  • Dave

    #2
    Re: DataTable and DataView

    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.D elete() 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.

    --
    Dave Sexton
    dave@www..jwaon line..com
    -----------------------------------------------------------------------
    "Jarod" <Jarod@discussi ons.microsoft.c om> wrote in message news:E2823E2E-47AC-4F89-BDB3-CA04560A81AE@mi crosoft.com...[color=blue]
    > Hey
    > I have dataTable let's call it dtMessages, and I have dvUserMessages. I am
    > doing st like this:
    > dvUserMessages = dtMessages.defa ultView;
    > 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(dvUserMessag es.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[/color]


    Comment

    Working...