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

B

Bennett Haselton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top