Filter Datatable based on Column names and not column values

Hi ,

Is there a way to filter datatable based on column names and not the column values.

If i am using select query to filter there I need to give some column values but I want to filter using column names.

I will have an excel sheet generated in every run, I will be having an array of predefined column names, say (, Test01, Test02, Test03…Testn). I will have to check in every excel sheet whether they have any of the column names between Test01 -Test0n.
Every sheet can have any number of column names from the predefined list.
So, if the excel sheet contains column names as Test01 and test02, so I need to filter the sheet containing only those 2 column names.
image
Any suggestion will be very helpful.
Thanks

First use the workbook.getsheet to check whether the column which you are expecting exist in the Excel or not.
If exist then you can use filter activity or linq to filter based on column name

Thanks @Shanmukh08 , but getsheets will give me the sheet name which I do not want because I will have only 1 sheet for which name will be hardcoded. So how can I filter and check if the column names exist or not without iterating.
I want to use Linq but the one used to filter datatable filters based on column values and not names

datatable.Columns.Contains(“your column name”). if this exist then you can do the filter

1 Like

@Shanmukh08 Thanks for your response, so in this case again, I will have to iterate all the column values and check which ever column name is present in dt and then use the Linq to filter the dt based on the column names found.
Is there a single Linq using which I can directly filter the datatable if it contains x,y, z columns?

@Faraz_Subhani

I think I did’t understand your requirement properly…

As per my understanding you have to check … Predefined list of string should be available in excel columns… for that use below code

YourPredefindListVariable.All(function(x) dttest.Columns.Contains(x)).ToString

dttest is your datatable

Above query will returns as True when all PredefindList values matches in Excel Columns otherwise its returns false

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