Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying data of only few columns to one more data table

I have a scenario where I get a data table with 65 columns and 100 rows. I need to create one more data table with all 100 rows, i.e. the same as the original data table but should be having only 5 columns out of 65 present in original table. Is there any way to achieve this without looping?

like image 300
satyajit Avatar asked May 31 '11 06:05

satyajit


1 Answers

Try DataView.ToTable method.

Use it like this:

DataTable newTable = oldTable.DefaultView.ToTable(false, "ColumnName1", "ColumnName2", "ColumnName3", "ColumnName4", "ColumnName5"); 
like image 79
Renatas M. Avatar answered Oct 28 '22 19:10

Renatas M.