Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting subset of columns from a datatable

Tags:

c#

I have a dataset of 15 columns. I want to generate an excel sheet with only 4 columns of that dataset. How can we select a subset of columns in to a datatable? Thanks, Rohit

like image 652
Rohit Ramname Avatar asked May 07 '12 17:05

Rohit Ramname


1 Answers

You can use DefaultView.ToTable for this:

var table = table.DefaultView.ToTable(false, "Column1", "Column2", "Column3");

Here's the documentation: DefaultView.ToTable Method

like image 125
James Johnson Avatar answered Oct 13 '22 03:10

James Johnson