Make a new DataTable with the same columns as another DataTable

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-06 04:27:47

问题


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.


回答1:


Try to use

myTable = table.Clone()



回答2:


Use the Clone method - it creates a copy of the schema (columns) only.
See DataTable.Clone



来源:https://stackoverflow.com/questions/5224926/make-a-new-datatable-with-the-same-columns-as-another-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!