How to find for a string i data table without using for each row

Consider i have a datatable as DT. where i have 5 columns named as col1, col2… col5.

i want to check whether “ABC” is present in col1 and “2020” is present in col5.
without using for each row.

@pthakre

you can use LINQ for it . e.g Getting the Count for these rows.

(From d In YourDataTableVar.AsEnumerable
Where d(“col1”).toString.Contains(“ABC”) And d(“col5”).toString.Contains(“2020”)
Select d).toList.Count

Can be used within an Assign Activity and returns an Integer

Hi,

We can check each column as the following.

existsCol1 = dt.AsEnumerable().Any(function(r) r("col1").ToString()="ABC")

existsCol5 = dt.AsEnumerable().Any(function(r) r("col5").ToString()="2020")

You can use them in If condition

existsCol1 and existsCol5

or

existsCol1 or existsCol5

Regards,

Thanks @Yoichi this is working
But how to add if i have some more numbers 2020-09-06 and i want to check it for “2020”

1 Like

Hi,

But how to add if i have some more numbers 2020-09-06 and i want to check it for “2020”

Can you try the following expression?

dt.AsEnumerable().Any(function(r) r("col5").ToString().StartsWith("2020"))

Regards,

Thanks @Yoichi,

This is working fine, but it should check both the values in same row at a time , it is checking but it is checking the values in column individually

1 Like

Hi,

it should check both the values in same row at a time

How about the following?

dt.AsEnumerable().Any(function(r) r("col1").ToString()="ABC" And r("col5").ToString().StartsWith("2020"))

Regards,

Working Fine…
Thanks @Yoichi

1 Like

Thanks for this, it helps me too.

Can I get the RowIndex number, where the string is Found. I need to Update the Excel with value "Found’ in column Z.

Thanks