Check whether a particular number is present in Data table

Continuing the discussion from Check whether a particular number is present in Data table or not:

@aksh1yadav can you please help me instead of searching thru Column name, can we search by column index, if yes what can be the code?

Hi @sapta_619

Welcome back to uipath community
Yes of course we can search via column index as well
–use excel application and pass the file path as input
–use a read range activity and get the output as a datatable named out_dt
–use a for each row loop and pass above variable as input to this activity
–inside this use a if condition like this, if you are checking whether the column D has value 123 in it or not
where 3 is the column index of column D
and usually the column index starts from 0

or even after read range activity without for each row loop we can check the value of a cell in a column from a particular row using a assign activity like this
out_value = out_dt.Rows(2)(3).ToString.Equals(“123”)
where this expression will return us a boolean expression whether the value exists or not
so the out_value is a variable of type boolean
where 2 represents the third row in the datatable, as the row index starts from 0 as well and
3 represents the fourth column in the datatable (you can mention both row and column index as you want, this is just an example buddy)

Hope this would help you
Cheers @sapta_619


Yes we can searching using Column Index also.

First Column - DataTableName.Item(0)

Second Column - DataTableName.Item(1)


1 Like

@Palaniyappan Thank you so much for quick reply :slight_smile:

I have an output data table where column names are not known but column index is known. As per my workflow I need to search “123” string from the entire datatable and check whether that string exists or not.

out_value = out_dt.Rows(2)(3).ToString.Equals(“123”)

This code will show me if result for 3rd row 4th column matches with string “123”, but i want to search only in 4th column for all rows present.

Any suggestions …?


  1. use Read Range activity to read the data from excel and will give you output as dataTable.

  2. Then use ForEach Row activity to iterate that dataTable and check with IF condition.

ForEach row in dataTableName
If row.Item(3).Tostring.Equals(“123”)
then found’
else not found

Here, item(3) referes to 4th Column.

Fine we can handle this in two ways buddy @sapta_619

–firstly simple but takes more step like this
use a read range and a for each row loop passing the output variable of read range as input to this for each row loop activity
Then inside the for each row loop use a if condition like this
And if this condition gets passed it will go to THEN part of if condition where we can write any activities


To get this done in a single and get the output readily as a datatable, we need to use SELECT method that would give use all the rows that matched with a particular value in a column

like this buddy @sapta_619
out_dt = (From rows In out_dt.Select
Where rows(yourColumnIndex).ToString.Equals(“123”)
Select rows).ToArray.CopyToDataTable

Cheers @sapta_619


You can use the for each row activity to achieve it.

Problem with for each row, it will search in 1st row first then 2nd row and will carry on, putting if logic here will show if that string does not exist in row 1 or row 2 … then it will proceed doing some job which i don’t want.

I want to check the datatable whether the string exists or not for all rows for respective column index

@Palaniyappan I tried using this but seems to be some syntax error

out_dt = (From rows In out_dt.Select
Where rows(yourColumnIndex).ToString.Equals(“123”)
Select p).ToArray.CopyToDataTable

If possible can you share an sample xaml

1 Like

may i know what was the error buddy @sapta_619

yah got it sorry typo mistake @sapta_619
it must be like this
out_dt = (From rows In out_dt.Select
Where rows(yourColumnIndex).ToString.Equals(“123”)
Select rows).ToArray.CopyToDataTable


What should be the variable type of out_dt?


actually it is the datatable that you actually have from read range, we are filtering the data using this select and copying again with those data alone to the same datatable outdt, thats what this COPYTODATATABLE depicts buddy
Cheers @sapta_619

1 Like

Ok. Gotcha it works, however i found another easy way to get it for my case… Something like:

  1. Extracted Data Table: To fetch the datatable.
  2. Output Data Table: To get datatable in string format
  3. val (Boolean)= datatable.contains(“123”)
  4. print val

cheers @sapta_619


You can also use filter on the datatable and if it gives you the count >0 means the string exist in the datatable.


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