How to skip columns using LINQ?

Need to filter some rows and skip the last column. Filtering rows can be easily done but How to skip the last column from getting included in the ouput data table by using LINQ?

And in general if there are large number of columns How can one skip the desired columns(say only 5 columns to be skipped out of 150)?

The above task is very easy using the filter data table activity, but when the data table is very large 600K rows and 150 columns, LINQ becomes necessary (isn’t it?).

Hi @kumar.varun2

This is the logic i have written on my custom activity for remove particular columns

 string[] tmpcolumnNames = datatable.Columns.Cast<DataColumn>()
                                 .Select(x => x.ColumnName)

            List<string> lst = tmpcolumnNames.ToList();

            foreach (string temp in columnNames)

            string[] tmp = lst.ToArray();

            datatable = datatable.DefaultView.ToTable(false, tmp);

it was written in c# and columnNames is the array of column names

1 Like

yes you can use this logic in

Okay. Thanks.

not mandatory

removing the last column we can do:

  • filterdatatable activity -col settings - remove - index: dtData.Columns.Count - 1

Working with DataTableVar.DefaultView.toTable(False, arrColSet)
arrColSet can be done by
DataTableVar.Columns.Cast(Of DataColumn).Select(Function (x) x.ColumnName.Except({“Col1”,“Col4”,“Col34”}).toArray


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.