LinQ where query for filtering datatable

So i was learning Linq and while i was on filtering datatable using where , i want to not include two items in the data table

here what i have done

Where Not row("City").ToString.Contains("Las Vegas") And Not row("City").ToString.Contains("London")

Basically, I have removed “Las Vegas” and “London” and it is actually working, but I want to minimize the code. Writing down the entire column name and then the city name will be very complicated.

Can’t we add two or three values directly inside the contains or at least after the first one?

Hi @indiedev91
try this below function in Assign Activity
ColumnName-> Need to FilterColumn
Value-> Column Value

Dt.AsEnumerable().Where(Function(x)Not x("ColumnName").ToString.Contains("Value1") And not x("ColumnName").ToString.Contains("Value2") And not x("ColumnName").ToString.Contains("Value3")).CopyToDataTable()

Refer the Img


1 Like

Hi @indiedev91 ,

Maybe a similar implementation could be implemented using a List/Array where we check if the all the values of the List are present in the data to search.

Where {"Las Vegas","London"}.All(Function(x)Not(row("City").ToString.Contains(x)))

Here, we could also replace {"Las Vegas","London"} by assigning this value to an Array/List variable and use that variable in the Expression.

1 Like

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