Unable to Copy datacolumn from one data table to another

后端 未结 6 907
独厮守ぢ
独厮守ぢ 2021-01-17 22:28

How can I copy 1 data column from 1 data table to a new datatable. When I try to do it, I get the error Column \'XXX\' already belongs to another DataTable.?



        
6条回答
  •  攒了一身酷
    2021-01-17 23:11

    No looping required , Refer this , Hope this should solve your problem...

    DataTable dt = new DataTable(); 
    //fill the dt here 
    DataTable dt2 = new DataTable(); 
    string[] strCols = {"Column Name to copy"}; 
    dt2 = dt.DefaultView.ToTable("newTableName", false, strCols);
    

提交回复
热议问题