# Linq query for datatable

**URL:** <https://forum.uipath.com/t/linq-query-for-datatable/726403>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, excel, activities\
**Created:** [13. März 2024 um 10:48 UTC](https://forum.uipath.com/t/linq-query-for-datatable/726403 "2024-03-13T10:48:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SunnyJha](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sunnyjha/32/401187_2.png) [@SunnyJha](https://forum.uipath.com/u/SunnyJha)\
**Post date:** [13. März 2024 um 10:48 UTC](https://forum.uipath.com/t/linq-query-for-datatable/726403/1 "2024-03-13T10:48:00Z")

</div>

Hi,  
I have an excel file which I read to a datatable say dt\_original. Now based on value in column A I want to segregate it into two datatables. If the cell of column A contains the keyword lets say “abc” then the whole row goes to datatable1 else datatable2. Now column A can have blank cells as well.  
Can we write this logic using linq query?

---

<div class="post-metadata">

**Author:** ![lrtetala](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@lrtetala](https://forum.uipath.com/u/lrtetala)\
**Post date:** [13. März 2024 um 10:50 UTC](https://forum.uipath.com/t/linq-query-for-datatable/726403/2 "2024-03-13T10:50:01Z")

</div>

Hi @SunnyJha

Filter the DataTable based on the values in column A containing the keyword “abc”

```auto
 dt1 = dt_original.AsEnumerable().
    Where(Function(row) Not row.IsNull("Column A") AndAlso row.Field(Of String)("Column A").Contains("abc")).
    CopyToDataTable()

```

Filter the DataTable based on the values in column A not containing the keyword “abc”

```auto
dt2 = dt_original.AsEnumerable().
    Where(Function(row) Not row.IsNull("Column A") AndAlso Not row.Field(Of String)("Column A").Contains("abc")).
    CopyToDataTable()

```

Regards,

---

<div class="post-metadata">

**Author:** ![mkankatala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mkankatala/32/484097_2.png) [@mkankatala](https://forum.uipath.com/u/mkankatala)\
**Post date:** [13. März 2024 um 10:51 UTC](https://forum.uipath.com/t/linq-query-for-datatable/726403/3 "2024-03-13T10:51:36Z")

</div>

Hi @SunnyJha

You can use the LinQ Expression,

```auto
-> Datatable1 = dt_Original.AsEnumerable().where(Function(X) (Not String.IsNullOrEmpty(X("ColumnA").ToString)) AndAlso X("ColumnA").toString.Equals("Keyword")).Copytodatatable()

-> Datatatble2 = dt_Original.AsEnumerable().Where(Function(x) (Not String.IsNullOrEmpty(x("ColumnA").ToString)) AndAlso (Not x("ColumnA").ToString().Equals("Keyword"))).CopyToDataTable()

```

→ Datatable1 contains the matched rows with the keyword in ColumnA.  
 → Datatable2 contains the unmatched rows with the keyword in ColumnA.  
 → Change the Column name and Keyword in the LinQ Expression based on your condition.

Hope it helps!!

---

<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:** [20. März 2024 um 08:32 UTC](https://forum.uipath.com/t/linq-query-for-datatable/726403/4 "2024-03-20T08:32:34Z")

</div>

Geschlossen, am 20. März 2024 um 08:32 UTC

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