Adding DataTable Rows To another DataTable

  • Thread starter Thread starter J. Babe
  • Start date Start date
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
 
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.
 
Back
Top