Using LINQ to extract key from the keyValue pair from Datatable using single line

Hi Team,

Suppose I am having a datatable as shown below:

Name Age
A 20
B 25
C 30
D 35

I need to use a LINQ to filter the datatable such that I have a value in a variable using single assign activity


String Result = Datatable.AsEnumerable().select (such that Name =“C”)

Somehow I need to have Value 30 in the result string.

Expectation : Result = 30

Hi @hacky

Welcome to UiPath community

You can try to achieve via Filter DataTable activity

Check out this XAML file

FiterBasedInput.xaml (9.3 KB)


HI @hacky

You can try with lookup datatable activity


Hi @hacky

You can try with LINQ expression

DtBuild.AsEnumerable.Where(Function(r) r("Name").ToString=InputVal).CopyToDataTable


we can do as above, also demonstrated the handling of empty filter result

I many scenarios it is prefered to create a lookup dictionary and take some benefits of

  • performance
  • keys checking

Hi @hacky

Remember that LINQ expression usually returns innumerable collections, you can get the first returned value if you know there is always a unique response.

Filtered_age = dt_variable.AsEnumerable().Where(function (dr) dr(“Name”).ToString=“C”).First().Item(“Age”)


Str=DT.Asenumarable.Where(Function(r) r(“Name”).Tostring=“C”).First().item(“Age”).Tostring