How to use LINQ for convert a DataTable to Dictionary in UiPath

In projects where an excel or data table needs to be read, it is a useful way to use the table as a dictionary structure and get the desired data in this way.

In this article we will look at how we can do this with “LINQ” expressions.

You can also make this structure by reading a ready-made excel file.

But let’s first create an example simple data table.
Let the table variable name be “dtEx”.


Then we create a “Dictionary variable” named “dicDtEx”.

To select the Dictionary variable;

  • Browse for Types
  • Type Name = System.collections.generic.dictionary
  • String/String — OK

We will use the LINQ expression with this variable and get the value we want.

dtEx.AsEnumerable.ToDictionary(Function(x) x.Item(“Name”).tostring, Function(x) x.Item(“Surname”).ToString)

In the LINQ expression we made above;

  • Reading our data table like a dictionary
  • When we write a name from the “Name” Column, we want it to output the Surname with the corresponding one from the “Surname” column.

Output like this;

1 Like

Hi @Nitya1
Great article. Thanks for sharing!

This post is marked Feedback which is used by forum admins and/or product owners to track product feedback and bug reports.

Please consider removing it as these feedback posts create additional filter work for forum admins :slight_smile:


Hi @Nitya1,

Thanks for a useful share.


1 Like