Convert a DataTable Column to a List in UiPath

In every business process automation we work with DataTable.

Let’s learn how we can convert a DataTable Column to a List in UiPath using a LINQ Query.

It may be used in different steps of the workflow basing on your conditions for that process.

Let’s look at the implementation now.

Step1: Drag and Drop a Build DataTable Activity in UiPath studio designer panel as mentioned below:

datatable column to list

Step2: Drag and Drop an Assign activity in the designer panel as mentioned below:

datatable column to list

Let’s understand what we have used in the above LINQ Query.

What is AsEnumerable()?

It is a generic method, which allows you to cast a specific type to its IEnumerable equivalent.

From row in DT.AsEnumerable()

Here AsEnumerable() method will returns an IEnumerable<DataRow> object.

This can be used in a LINQ expression or method query.

So, from this we are iterating each row from a DataTable.

Select Convert.Tostring(row(“Name”))).ToList()

Now, we are converting each row value that is related to that particular column value to a string and add it to List.

This is how the LINQ expression will work in this case of converting a DataTable column to a list.

Step3: If you want to get each value from that List you can use for each and iterate it as mentioned below:

datatable column to list

Step 4: If you want to see the output of this List in a message box then you have to use the below-mentioned code:

String.Join(" ",DTToList)

Here we are joining the List which is separated by a space.

Note:

The column name that we are mentioning in the LINQ query is a specific one that needs to be taken a look at if you are facing any errors.

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *