Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove columns from DataTable in C#

Tags:

c#

asp.net

I have a DataSet which I get a DataTable from that I am being passed back from a function call. It has 15-20 columns, however I only want 10 columns of the data.

Is there a way to remove those columns that I don't want, copy the DataTable to another that has only the columns defined that I want or is it just better to iterate the collection and just use the columns I need.

I need to write the values out to a fixed length data file.

like image 573
Brian G Avatar asked Sep 16 '08 18:09

Brian G


1 Answers

Aside from limiting the columns selected to reduce bandwidth and memory:

DataTable t; t.Columns.Remove("columnName"); t.Columns.RemoveAt(columnIndex); 
like image 180
Tom Ritter Avatar answered Sep 24 '22 11:09

Tom Ritter