Search value in the datatable


#1

I created a Datable with Scrapping Data and I want to select the line where more conditions.
In example, the number in first colum is “23” and the seventh column contains the letter “A”.

I searched… I found “DataTable.Select méthode (String)” but it’s not works.


#2

Please provide your code or a similar enough example if you can’t share it directly.

Unfortunately “it doesn’t work” doesn’t give enough information to diagnose. But I can assure you that .Select method does work, so there has to be something specific to how the DT looks or how you’re using it.

Regards,
Andrzej


#3

DT_ExtractDataTable.Select(“Number=23” and Column7 contains “D”).
The syntax isn’t correct but after I want line who response by the select


#4

Can you try

DT_ExtractDataTable.Select(“Number=23 and Column7 like ‘%D%’”).


#5

Not works : compiler error… but how read the number line after ?


#6

May be something with the quotes, can you share your code. I did not understand “but how read the number line after

Do you want to know how to read the output? The output is a DataRow Array and you can get the values by iterating in foreach loop.


#7

try this:
for each row in ExtractedDatatable
{
if(Convert.ToString(row.Item(< columnIndex >)).Exact(“23”)=True)
use assign activity : value= Convert.ToString(row.Item(< columnIndex+1/ or any other column index >))
}


#8

=>> Convert.ToString (Row.Item(2))="23 instead of Convert.ToString(row.Item(< columnIndex >)).Exact(“23”)=True

But : I would like to return the number of row who find the value.

Fist solution : counter with i++ and return i but I don’t like (vvaidya)
Second solution : use method with row but which ? (item ordinal ? other ?)

Thanks all


#9

@Lorennzo I would like to return the number of row who find the value.

Do you mean number of rows returned?

dtRow = DT_ExtractDataTable.Select(“Number=23 and Column7 like ‘%D%’”)

rowsfound = dtRow.length


#10

Length is (definition) “The total number of elements in all the dimensions of the Array”.
Example :
1 2 3
ab ed ef
fd ed ea
ed ac ax

I select the Third line in my datatable with colum1=ed and colum3=ax
I want to return 3 (the line three)


#11

As per your requirement, the output should be line 3. If you want to find out the line numbers, you have to use foreach loop of DataRow array since the result can be > 1 rows.Inside the foreach loop use the below logic:

foreach(row in RowArray)
{
int linenum = DT_ExtractDataTable.Rows.IndexOf(row);
}


#12

Sorry, return always 1 for me.
An idea, I found maybe a method : BinarySearch but works only on a column I think.


#13

@Lorennzo if return is always 1, below is the logic and no need of foreach

dtRow = DT_ExtractDataTable.Select(“Number=23 and Column7 like ‘%D%’”)
int linenum = DT_ExtractDataTable.Rows.IndexOf(dtRow(0)) + 1; (+1 since index starts from 0)


#14

to get the row number use assign int index = dt.Rows.IndexOf(row);


#15

It works - Thank’s vvaidya and palindrome
It was my first Uipath progam !


#16

HI,
I have two data tables,say dt1,dt2…i have to take one value say id, from dt1 and i have to search in dt2 with all id’s that are in dt2, and if found i have to copy remaining columns data from dt1 to dt2 for that id.can anyone please help me regarding this.in what way i can use select function.
thanks