Adding DataTable Rows To another DataTable

J

J. Babe

I was wondering how to add the first 20 rows from one datatable to
another datatable without getting the error:
This row already belongs to another table
 
K

Kevin Spencer

You need to "clone" the DataRow for the other table. DataRow doesn't
implement ICloneable, so you will need to create a loop that creates a new
row in the second DataTable, and copies the data contained in the columns of
the first DataTables row to the new row created for the second DataTable,
and then adds the new DataRow to the Rows Collection of the second
DataTable.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 

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,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top