copy row from one datatable to another

G

Guest

I have read posts and tried many things and I am not getting how to do this.

I have a datagrid bound to a dataset (the source). When a row is selected
on the datagrid, I need to duplicate that row into another dataset (the
destination). The destination dataset will be bound to a a repeater that is
located below the datagrid.

I cloned the source dataset to the destination and have datatables
referenced for both datasets. I have primary keys defined for each datatable
and the schemas are identical.

The datagriditem only contains a portion of the columns from the source
dataset. The repeater will display more of the columns from the destination
dataset.

I can get the primary key for the selected datagriditem, but that is as far
as I can get.

How do I do copy a selected row to the destination dataset? I am using
asp.net 1.1 with code-behind of vb.net. If needed, I can post the code that
I have so far.

Thanks, Alex
 
G

Guest

Hi Alex,

One way you can copy row from one datatable to another datatable is to use
datatable. LoadDataRow method. Following snippet code shows how to do it:

Foreach (row As DataRow in sourceTable.Rows)
destinationTable.LoadDataRow(row.ItemArray, False)
Next


HTH

Elton Wang
 
R

Robbe Morris [C# MVP]

That sample demonstrates this along with reminding you
that it sets a reference on each row to the new DataTable.

I assumed the poster didn't want to copy every row.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net
 

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

Top