Assign variables in Select

Hi All ,

I am trying to get a variable - assign it to a generic value and then use that in the select statement , is this doable in Uipath.

Thanks

1 Like

yes.

dataTable.Select(“Age>=”+dt1 ) or dt1.ToString

1 Like

Hi @vvaidya

I am getting a “column not found” error when I use the select function.

Did you check Add header in read range?

I did the add headers and specified the range

Check for any space and remove in Excel header for Age column

@vvaidya I encounter the following after that stage

Changed the Type argument and its not throwing an error

1 Like

Hi Guys,

I have the below error, when trying to filter using select statement as below,

dt2.Select(“Month =”+“'”+month+“'”+" AND TranType =“+”‘“+tranType+”’“+” AND LineCat =“+”‘“+lineCat+”’“+
" AND Total Count =”+“'”+totalCount+“'”+" AND Total Amount =“+”‘“+totalAmount+”’")

ERROR:

Message: Syntax error: Missing operand after ‘Count’ operator.

Source: Assign

Exception Type: SyntaxErrorException

System.Data.SyntaxErrorException: Syntax error: Missing operand after ‘Count’ operator.
at System.Data.ExpressionParser.Parse()
at System.Data.DataExpression…ctor(DataTable table, String expression, Type type)
at System.Data.DataTable.Select(String filterExpression)
at lambda_method(Closure , ActivityContext )

I’m assuming because of a space between the column header value “Total Count” & “Total Amount” columns,

Any help is appreciated,

Thanks.!

Well @Dilli

just use like that and let me know :slight_smile:

dt2.Select("Month ="+"'"+month+"'"+" AND TranType ="+"'"+tranType+"'"+" AND LineCat ="+"'"+lineCat+"'"+" AND [Total Count] ="+"'"+totalCount+"'"+" AND [Total Amount] ="+"'"+totalAmount+"'")

Regards…!!
Aksh

5 Likes

It works like a charm mate. So it’s these braces needed if the header name has a space between words. Isn’t it ? Thanks.!

Yes :slight_smile:

how to convert generic value variable into String datatype

i have scenario were i have to apply if condition on database column name “State” and value for this column would be “open”.
So i used Get Row item to get State column data, after that using if condition like State=Open the it is giving me error like below

image

Hey @thakurashish55525

Use State.Tostring() =“Open” in your If condition.

I was getting the exact same error as saivig:

For me the solution turned out to be a syntax issue: an extra set of single apostrophes was needed. I was able to filter by columns that had variables of Int32 Type in the format shown above when filtering rows in the table, but every time I tried to filter on a Text Type variable column I’d get the “column not found” error.

dataTable.Select(“author = '” + authorName.ToString +“'”)

  • double-quote | column-header | equal-sign | single-quote | double-quote | plus-sign | text-variable | plus-sign | double-quote | single-quote | double-quote
  • authorName was already a String variable so .ToString is not necessary
1 Like

Hi,

image

Regarding the syntax, can I replace the column-header with column-index, and how ?

Thanks

.Select doesn’t support it, but you can work around by using dt.Columns(yourIndex).ColumnName instead of a hardcoded column name.

Hi @andrzej.kniola,

Thanks, I think I am close to it but still got the error. The expression contains undefined function call DT.Columns()

The column I want to compare with the string variable is Column 0. My syntax is:

DTSelect(“DT.Columns(0).ColumnName = '”+string variable+“'”).CopyToDatatable

Where did I make the mistake ?

A typo on the syntax, it should be:

DT.Select(“DT.Columns(0).ColumnName = '”+string variable+“’”).CopyToDatatable