Filtered Datatable with array of string

Hi all,

I am trying to filter the data table using an array of string. none of the solutions in the forum seem to be working.
I want to do 2 filter

One contains
and one not contain.

want to avoid using data table filter activity.

Thanks all :slight_smile:

Hi,

How about the following expressions?

One contains

dt = dt.AsEnumerable.Where(function(r) yourStringArray.Contains(r("ColumnName").ToString())).CopyToDataTable()

and one not contain.

dt = dt.AsEnumerable.Where(function(r) not yourStringArray.Contains(r("ColumnName").ToString())).CopyToDataTable()

Regards,

I tried that , but it wont allow me to put on boolean.

Hi,

Is there any error?
Can you share your data and what you expect in details?

Regards,

No, there’s no error but i want to use that condition in flow decision or IF statement. but it’s saying data table can’t convert to boolean and if i remove copytodt then its saying can’t convert dt row to boolean

Hi,

How about the following? It returns true if there is one or more item which match with one of your string array.

hasContains = dt.AsEnumerable.Any(function(r) yourStringArray.Contains(r("ColumnName").ToString()))

Regards,

2 Likes

thanks that work. i was missing extra () when i tried it.

I m having this eorror for " The source contains no DataRows. "

Thanks

Hi,

I m having this eorror for " The source contains no DataRows. "

Do you have the error at CopyToDataTable()?
If so, you need to check number of data rows in advance. And if the number is 0, you need to do other such as dt = dt.Clone() using if activity as the following image.

Regards,

2 Likes

Yes , i m trying to seperate the datatable.
Sometime i could come with zero row and sometime it could be mixed.
Dont want to use filter table as i would have to hard code the filtering.
IF there’s no row i want to just assign nothing. so dt.clone won’t do for me

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