Linq query to filter datatable

I’m trying to select all rows from a datatable that have column values present in a list. I would prefer to use a linq query as the list will be dynamic and not ideal for filter data table activity

For example, DT1
Col1, Col2
1, dog
2, cat
3, tree
4, big dog

list_for_col2 = “dog, cat”

The output datatable should be
DT2
Col1, Col2
1, dog
2, cat
4, big dog

2 Likes

Like this:

Processusvierge.zip (8,2 Ko)

The workflow uses LIKE to find if the word is in the column.

@twatson
give a try on

(From s in searchtermlistvar
From r in yourdatatablevar.AsEnumerable
where r(YourColumnNameOrIndex).toString.Contains(s)
Select r).CopyToDataTable

keep in mind .CopyToDataTable thtows an exception if no rows are returned. Additional Handling of this is possible as well

Updated Flow And LINQ:

LINQ:
(From d In dtData
Where KeyWords.Any(Function (x) d(1).toString.Contains(x))
Select r = d).ToList

Starter Help:
DT_Filter1Col_ByKeyWordList.xaml (9.2 KB)

5 Likes

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