Need To filter excel column by using LINQ query

Hi All,

I Need to filter the excel file based on starts with value by using linq query.
Can anyone please help me.

ex- i have column with the header name of CD

I need to filter the rows if it starts with D or E or K or L or R or S

1 Like

Test with:

filteredDt = dt.AsEnumerable.Where(Function(r)  {"D", "E", "K", "L", "R", "S"}.Any(Function(x) r("CD").ToString.ToUpper().StartsWith(x)))

No It didnt work, Just confirm me, filtereddt is datatable var type right?

i got this error=

Sorry, I was not at my computer so I couldn’t test. You need to add .CopyToDataTable() also to make it work. Yes both dt and filteredDt should be DataTable.

Thanks mate!! this works fine, One last query please what if i have to filter with only one value which means starts with S.

filteredDt = dt.AsEnumerable.Where(Function(r) (“S”)(Function(x) r(“CD”).ToString.ToUpper().StartsWith(x))).copytodatatable()

does this work?

For checking one letter:

filteredDt = dt.AsEnumerable.Where(Function(r) r("CD").ToString.ToUpper().StartsWith("S")).CopyToDataTable()

Thanks a ton both works fine :grinning:
If possible share me a link where i can learn query by myself

Here is the Tutorial for LINQ @ashokkumar_e


Refer this learning doc @ashokkumar_e


[quote="[HowTo] Overview on different options for grouping data and processing the groups, post:1, topic:290708"]
ping data and processing the grouped data is a common scenario e.g. when the grouped data is to aggregate like summing up, find maximum, get the average or concatening items. Lets have a look on following data: [grafik] A possible scenario could be: Create a report containing follow

Thanks @Gokul

Hi @ashokkumar_e,

Kindly go through the link, it will help you to filter the datatable.


1 Like