Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a new DataTable with the same columns as another DataTable

I want to create a new DataTable that has the same columns as another DataTable.

Currently, I do the following:

DataTable myTable = new DataTable();
myTable = table.Copy();
myTable.Clear();

Then, I import rows into myTable as needed.

Is there a more efficient way of doing this? Right now if table is large, then there is a lot of unnecessary copying of rows going on.

Thanks.

like image 314
John Avatar asked Mar 07 '11 20:03

John


People also ask

How do I copy DataTable from one DataTable to another?

Copy() creates a new DataTable with the same structure and data as the original DataTable. To copy the structure to a new DataTable, but not the data, use Clone().


1 Answers

Try to use

myTable = table.Clone()
like image 75
Stecya Avatar answered Oct 15 '22 03:10

Stecya