Datatable.Select using a variable for the column value

I have no problems filterin a data table using the Select method when I use a literal as the value to select for the column, but for some reason I am unable to get it work with a variable. It appears to be returning no values. I probably have the incorrect syntax:

Assign CountryRow = in_CountriesDT.Select(“Country = ‘in_CountryName’”)

CountryRow is an array of data rows. in_CountriesDT is the datatable passed into the workflow. in_CountryName is a string argument containing the country name passed into the invoked workflow. “Country” is the column name in the data table. There is one row matching the country name, so it should return a single row. It works fine when in_CountryName is replaced with a literal.

Hi,

Please note that when using variables in select, you need to separate them from the text with a + sign. Also, please use square brackets for column name. In this example:
Assign CountryRow = in_CountriesDT.Select(“[Country]=‘" + in_CountryName + “’”)

1 Like

Many thanks. That does indeed work. Can you point me at where this syntax is documented? I have been unable to locate a syntax reference source and it’s not at all intuitive!

Many thanks again.

1 Like

I found this which may be helpful for others https://www.csharp-examples.net/dataview-rowfilter/

Actually this is the proper .Net docs link https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=netframework-4.8

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