Assign variables in Select

datatable

#1

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


#2

yes.

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


#3

Hi @vvaidya

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


#4

Did you check Add header in read range?


#5

I did the add headers and specified the range


#6

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


#7

@vvaidya I encounter the following after that stage


#8

Changed the Type argument and its not throwing an error


#9

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.!


#10

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


#11

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.!


#12

Yes :slight_smile:


#13

how to convert generic value variable into String datatype


#14

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


#15

Hey @thakurashish55525

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


#16

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

#17

Hi,

image

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

Thanks


#18

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


#19

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 ?


#20

A typo on the syntax, it should be:

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