简体   繁体   中英

Selecting specific columns from a dataTable and copy it to another DataTable

I have a DataTable Dt1 and another DataTable Dt2.

Dt1 contains many columns and rows and Dt2 is basically empty

I know I should use Dt1.Select to select the specific DataTaRow [] but how can I copy them to Dt2

DataRow [] row = Dt1.Select("ID,MIN_VALUE,MAX_VALUE");

how can i copy them to Dt2?

For .Net Framework 3.5+

You can use CopyToDataTable method.

Returns a DataTable that contains copies of the DataRow objects, given an input IEnumerable object.

DataTable dt1 = new DataTable();
DataRow[] dr = dt.Select("Your string");
DataTable dt2 = dr.CopyToDataTable();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM