Pass array variable in Datatable.Select()




I am trying to do the following:

  1. Create a variable and assign an array of strings. say variable name = item
  2. dataTable.Select(“Column =” + item) - This is not working as expected.

Requirement: I need to select the columns which are equal to each array item.
say if array = {“hi”, “hello”, “bye”}, I want to filter the datatable for “hi” and then for “hello” and later for “bye”. This iterations are done using For each but I am unable to pass this array variable in Select() method.

How can I do this?

Kindly help!

Many thanks in advance!



I would just use the Array variable for this using either LINQ or Lambda
For example:
arrVariable.Where(Function(item) item = “hi” or item = “hello”).ToArray()
will do multiple criteria

(From item In arrVariable Where item = “bye” Select item).ToArray()
will do just one and you can have 3 of these for each word



Hi ClaytonM,

Thanks for your response.

Can this be used to filter Data table or excel sheet?



Yeah you can use this for DataTable like:
datatableVariable.AsEnumerable().Where(Function(row) row(“column”).ToString = “text”).CopyToDataTable()
(From row In datatableVariable.AsEnumerable() Where row(“column”).ToString = “text” Select row).CopyToDataTable()

For Excel Sheet filtering you would need to use keystroke combinations or element clicks, however you can store the sheet into a datatable, filter it the way you want, then output it back to the Excel file, which is probably what I would do (unless you are wanting to use the built-in Filter feature of Excel).



Hi @ClaytonM,

can you please give an example of where I put the code?



Hi @martin.grimaldo

There are different ways to utilize the filtered datatable, but ideally you can just use an Assign activity to store your new datatable or array of datarows into a variable, then process them using a ForEach activity.

Similarly, you can do the same to create an array of rows (from within the original datatable) to process, which in many cases is a better use since you can update the original datatable with values. For example, Assign arrRows(i).Item(“column”) = “newtext” and it updates it in the datatable



Could you help me? I need to save into an array of rows the result from a filtered datatable using Select. But it always returns me zero data, I have already verified the data in datatable with an output message and everything seemed fine.



Hi may I drop some similar question here?

I’m trying to implement something like this
DT.Select(“ColumnName in {“item1”, “item2”, “item3”}”).copytodatatable

How can I replace this list/array {“item1”, “item2”, “item3”} with a list/array-type variable?
Basically what I need to do is to convert Datatable.Columns into {"", “”} clause.

I have tried
For each row in DataTable
Add to collections {collection: new List of String, Item: row.item(“columnName”)}.ToString

New DT = DataTable.Select((“ColumnName in List”)

then I got this error:
“The items following the in keyword must be separated by commas and be enclosed in parentheses uipath”