Select item in datatable

Hello,

How do i check if one column of my datatable contains for example the name “john”…

Something like this : varDT.Select(“ColumnA”.Contains(“John”)).ToString

Thank you

@Maroua302 Do you want to just Check if the name John is present ?

Yes please

Use this below code @Maroua302
Boolean Variable = FilteredDT.AsEnumerable.Select(Function(y) y(“ColumnName”).ToString.Trim).ToArray().Contains(“John”) .
You will get an boolean variable as a output.

5 Likes

Hi @Maroua302,

For this you can use Lookup Data Table activity to get RowIndex containing value "John"
by using you’ll able to get the rowIndex,
If there’s no such value in that column RowIndex var will get value as -1
so In If activity you can use condition as —> RowIndex=-1 to decide, if execution goes in Then section then, value is not there in a column. Else value is there. (RowIndex has value other than -1)

Here’s one sample workflow for your better understanding —> test.xaml (6.8 KB)
See build datatable and lookup value in Lookup datatable activity, and run the workflow.

Hi @Maroua302
If i got u right! You wanted to check for a name inside particular column in datatable.
Here is my solution for you…

You can loop over that data table using " For each row" activity.
later use a “If” activity and give a condition in this format

  • row(“ColumnA”).ToString.Contains(“John”)
    Hope this helps you :smiley:

@Manish540

Hello, thank you for your response, unforthunaly, it does quite work for me! With your instruction, i always get false as result. But with this code : row(1).ToString.Contains(“ANZAXA”)

It find the word. I trying to use the function, so that i don’t have to loop inside the dt.

Cheers

Hello @ppr

Can you help with this issue please ?

@Maroua302

check if one column of my datatable contains for example the name “john”

can be interpretated in many directions:

  • True if any row contains John in columnA
    dtData.AsEnumerable.Any(Function (x) x(“ColumnA”).toString.Contains(“John”))

*return all john rows
dtData.AsEnumerable.Where(Function (x) x(“ColumnA”).toString.Contains(“John”)).toList
dtData.Select("[Name] LIKE ‘%john%’").toList

About the datarows and Copytodatatable:
we can also expect that a filter result can be empty. A copytodatatble would fail
So for this case we let us return list of Datatrows drResult
and in an if activity we do check:drResult.Count > 0
True. dtResult = drResult.CopytoDatatable

Let us know your feedback
If it is not working share some sample data and more detail result definition with us
Thanks

Did you tried Filter DataTable? Any feedback on this from your end?

2 Likes

Hello @ppr

Thank you very much for you explanations.

The thing is that i have a datatable that scraped from a web app, later i have to iterate on each row to do some manipulations, than for each row, i have to download a file and name it as the name of that row…

So what i did up to now, i converted the datatable to an array, than i used a for each to iterate on each row. But stuck on how to check weither that row, contains for example the word “John”, so that i can be sure that’s the right one, to be named with that name.

Hope this clears things for you !

Cheers and thanks again !

@Maroua302
Unfortunately it didnt cleared.
On a certain stage you have a datatable and in its rows and columns you want to do a check, count or filter.

So with debugging and breakpoint setting you are able to inspect the data inside the datatable.

Finaly you can share with us in a form like:

Datatable:
Col1, Col2
A,1
B,2
C,3

check to do: Filter, Find, Count…
Expected result: …

Give a try on a clear requirement description and do help us with this Thanks

@ppr

Ok, so let’s say… we have a table on a web application, which contains this :

ColumnA-----ColumnB
1---------------internet explorer is the best
2---------------chrome is the best
3---------------firefox is the best

I use data scraping to get this rows…

So on each row, i have to do multiple manipulations… after i’m done, i have to download a file which is inside that row, than save it with a specific name. To do so, i have to check weither it’s internet explorer or chrome or firefox… so that i save it with the right name…

I managed, to iterate on all rows and do all manipulations needed, but stuck on how to check which one of the rows is running now so that i save the file with the correct name…

I tried to use a switch so to check which row is running now and save it on a variable… but couldn’t find out how…

Something like this :

Switch Expression : FilteredDT.AsEnumerable.Select(Function(y) y(“ColumnName”).ToString.Trim).ToArray().Contains(“John”)

Case1 : “John”
Case2 : “Eric”
Case3 : “Angel”

Is this clear ? Sorry can’t share the data… and for my broken english…

@Maroua302
this helped for the next steps.

is the list of Searchterms (John, Eric,Angel…) fixed so that we can store it in a config car e.g. String Array?

@ppr

Something like this, inside an array…

Phrase : Chrome is better…

Switch : Expression? contains…

Case1 : “Internet”
VarName = item.ToString
Case2 : “Chrome”
VarName = item.ToString

@Maroua302
have a look on this prototype:
Maroua302.xaml (8.1 KB)

2 Likes

@ppr

Thank you so much, that’s what i was looking for !!

@Maroua302
Perfect just play with it and let us know your remaining open questions. Happy Automation :+1:

1 Like

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