how can I create a copy of a DataRow that lasts after datatable is cleared?

Discussion in 'ASP .Net' started by Bennett Haselton, Nov 11, 2004.

  1. If I have just filled a DataTable in a typed DataSet with a single
    row, is there a way I can make a copy of that row, so that I can clear
    the DataTable in that DataSet and use it for another query, but my
    copy of the row will be preserved?

    If I try to do something like this:

    this.oleDbWbuserAdapter.SelectCommand.CommandText =
    "SELECT * FROM wbuser where username='bennett';";
    this.oleDbWbuserAdapter.Fill(ds1.wbuser);
    dsLocalDataSet.wbuserRow currRow = ds1.wbuser[0];

    ds1.Clear();

    this.oleDbWbuserAdapter.SelectCommand.CommandText =
    "SELECT * FROM wbuser where username='bennett2';";
    this.oleDbWbuserAdapter.Fill(ds1.wbuser);

    // this won't work; reference to currRow is no longer valid
    Response.Write(currRow.username);

    (where dsLocalDataSet is a typed DataSet class containing a table
    called "wbuser") then this won't work, because currRow just refers to
    row zero of the ds1.wbuser DataTable, and when I call ds1.Clear(),
    currRow disappears.

    On the other hand DataRow doesn't appear to have a built-in method for
    making a copy of itself. The ds1.wbuser DataTable class does have a
    member method called NewwbuserRow() generated for it, but it doesn't
    take any arguments, so I can't pass an existing wbuser row to it and
    make a copy. Is there some way to make a copy that I can refer to
    later in the code, even after I've cleared out the dataset object and
    reused it for another query? Or do I have to use a different dataset
    object for every query, if I want to keep the row objects around so
    that I can refer to them later in the code?

    -Bennett
    Bennett Haselton, Nov 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,031
    paul.mariotti
    Sep 28, 2007
  2. ypul
    Replies:
    3
    Views:
    41,520
  3. Shawn
    Replies:
    3
    Views:
    30,345
    Robbe Morris [C# MVP]
    Mar 9, 2005
  4. NOBODY
    Replies:
    2
    Views:
    1,839
    Dario
    Feb 2, 2004
  5. Rob Dob
    Replies:
    0
    Views:
    460
    Rob Dob
    Sep 28, 2006
Loading...

Share This Page