# How to loop datatable using LINQ?

**URL:** <https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596>\
**Category:** Something Else\
**Tags:** looping, linq-loop, for-each, linq-query, linq, for-each-datatable, loop, for-each-row, system, activities\
**Created:** [September 16, 2022, 1:30pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596 "2022-09-16T13:30:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muralikrishna\_Surve](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/muralikrishna_surve/32/253024_2.png) [@Muralikrishna\_Surve](https://forum.uipath.com/u/Muralikrishna_Surve)\
**Post date:** [September 16, 2022, 1:30pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/1 "2022-09-16T13:30:01Z")

</div>

I want to loop the Datatable values using **LINQ**.

Same like as we normally do using ‘For Each Row’ activity.

How to loop the datatable using **LINQ**?

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [September 16, 2022, 1:31pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/2 "2022-09-16T13:31:38Z")

</div>

> [@\[HowTo\] - Exploring the LINQ Universe (VB.Net)](https://forum.uipath.com/t/howto-exploring-the-linq-universe-vb-net/325667):
>
> LINQ (Language-Integrated Query) is part of the .NET framework and offers capabilities for interacting with data, objects, or other sources within a particular syntax. This HowTo elaborates on the availability of LINQ and explores the offered functionalities Current Version of this topic is DRAFT and will be finalized / enhanced soon Introduction Let’s recap the Example of LINQ from [[HowTo] - First Start with LINQ (VB.Net)](https://forum.uipath.com/t/howto-first-start-with-linq-vb-net/318964). Sample data: myNumbers | List (Of Int32) = {12,34,5,8,10,2,15,7}.to…

---

<div class="post-metadata">

**Author:** ![Shubham\_Dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shubham_dutta/32/266407_2.png) [@Shubham\_Dutta](https://forum.uipath.com/u/Shubham_Dutta)\
**Post date:** [September 16, 2022, 4:26pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/3 "2022-09-16T16:26:05Z")

</div>

Hi @Muralikrishna_Surve ,  
Please go through the below youtube video:

[![](https://global.discourse-cdn.com/uipath/original/4X/1/9/8/198ac3341519818f870b825de85319da8b726d10.jpeg "UiPath | LINQ Cast Function | Loop Through Rows and Columns of Excel / Table using LINQ | Convert") ](https://www.youtube.com/watch?v=HFam-My6T4k)

You will get a clear understanding.

Thanks & Regards,  
Shubham Dutta

---

<div class="post-metadata">

**Author:** ![postwick](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/postwick/32/227083_2.png) [@postwick](https://forum.uipath.com/u/postwick)\
**Post date:** [September 16, 2022, 4:26pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/4 "2022-09-16T16:26:57Z")

</div>

LINQ doesn’t really work that way. Why not just use For Each Row? It’s what it’s meant to do.

---

<div class="post-metadata">

**Author:** ![Shubham\_Dutta](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shubham_dutta/32/266407_2.png) [@Shubham\_Dutta](https://forum.uipath.com/u/Shubham_Dutta)\
**Post date:** [September 18, 2022, 11:52am UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/5 "2022-09-18T11:52:07Z")

</div>

Hi @Muralikrishna_Surve , if you have no more queries please mark the solution and close the thread.

Thanks & Regards,  
Shubham Dutta

---

<div class="post-metadata">

**Author:** ![ashwin.ashok](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashwin.ashok/32/300916_2.png) [@ashwin.ashok](https://forum.uipath.com/u/ashwin.ashok)\
**Post date:** [September 18, 2022, 1:15pm UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/6 "2022-09-18T13:15:34Z")

</div>

Hi @Muralikrishna_Surve

I agree with @postwick .  
Is there any specific reason for wanting to use [LINQ](https://thecodingtheory.com/linquist/)?

It entirely depends on the requirement, but if you want to explore solutions using code, then take the **Invoke Code Activity** out for a test run:

![image](https://global.discourse-cdn.com/uipath/original/4X/9/a/7/9a79d258266e471df55f19624291490e2a37e3fd.png)

```auto
For Each row As DataRow In dt.AsEnumerable()
Console.WriteLine(row(0))
Next row

```

[invoke\_Code\_Example.xaml](https://forum.uipath.com/uploads/short-url/o5kzt0y7JkHQRrHmuipWox6Ll7a.xaml) (7.3 KB)

**Kind Regards,  
Ashwin A.K**g

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 13, 2022, 5:57am UTC](https://forum.uipath.com/t/how-to-loop-datatable-using-linq/473596/7 "2022-10-13T05:57:12Z")

</div>

Closed on October 13, 2022, 5:57am UTC

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