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

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

1 Like

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