# Compare Datatable values with array using linq

**URL:** <https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196>\
**Category:** Activities\
**Tags:** linq, datatable, system, activities\
**Created:** [2024 年 9 月 20 日午前 5:59 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196 "2024-09-20T05:59:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashashwini2322](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yashashwini2322](https://forum.uipath.com/u/yashashwini2322)\
**Post date:** [2024 年 9 月 20 日午前 5:59 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/1 "2024-09-20T05:59:51Z")

</div>

Hi,I have datatable ,and and array of string and i want to compare datatable value with array values,after compare need those data in a datatable using linq query?

Below is an example:

arrStr={“not required”,“no template required”}

dt\_table

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/6/b/66b5de343adde8239d6a971a16698357d2b19194.png)

and the final output will be in datatable  
**Output:**  
dt\_Final

 ![image](https://global.discourse-cdn.com/uipath/original/4X/f/2/a/f2ad17a454ef6b5874399ce16016ca7e3fe858fd.png)

Anyone help me writing linq query for the above scenario.Thank you

---

<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:** [2024 年 9 月 20 日午前 6:14 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/2 "2024-09-20T06:14:26Z")

</div>

Hi @yashashwini2322

Use below query

```auto
DT = (From row In DT.AsEnumerable()
              Where arrStr.Contains(row("ColumnB").ToString)
              Select row).CopyToDataTable

```

 ![The image shows a workflow sequence for an Excel automation task, which includes assigning string values, reading a range from an Excel workbook, modifying data, and writing the results back to the workbook. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/0/3/3/03350a94ff9cc4cf6f70cd5f49d86e7ce8800a57.png)

**Input:**

![The image shows an Excel spreadsheet with two columns labeled "ColumnA" and "ColumnB," containing various text entries such as "CS," "SM," "required," and "not required." (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/3/7/3/3737e2804f41f92eaffcedf76b35abba55f58955.png)

**Output:**

 ![An Excel spreadsheet with two columns labeled "ColumnA" and "ColumnB," containing four rows of data with codes in ColumnA and corresponding status messages in ColumnB. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/6/e/e/6ee7f1cb35dbc7e98375c9a417a651d5b92abb44.png)

Regards,

---

<div class="post-metadata">

**Author:** ![yashashwini2322](https://avatars.discourse-cdn.com/v4/letter/y/e9a140/32.png) [@yashashwini2322](https://forum.uipath.com/u/yashashwini2322)\
**Post date:** [2024 年 9 月 20 日午前 7:15 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/3 "2024-09-20T07:15:06Z")

</div>

Hi,Thanks for the query help but,same linq query is not working for the below table.Any modification needed for query.

![image](https://global.discourse-cdn.com/uipath/original/4X/4/3/b/43b2807a87fc302bdeaea308558d8548a920b5ee.png)

---

<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:** [2024 年 9 月 20 日午前 7:21 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/4 "2024-09-20T07:21:30Z")

</div>

@yashashwini2322

I’ve changed the query, try this

```auto
DT = (From row In DT.AsEnumerable()
              Where arrStr.Any(Function(str) row("ColumnB").ToString.ToLower().Contains(str.ToLower()))
              Select row).CopyToDataTable()

```

Regards,

---

<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:** [2024 年 9 月 20 日午前 8:34 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/6 "2024-09-20T08:34:42Z")

</div>

@yashashwini2322

Try this

```auto
DT = (From row In DT.AsEnumerable()
      Where arrStr.Any(Function(str) row("ColumnB").ToString().ToLower().Contains(str.ToLower()) AndAlso
                                   row("ColumnA").ToString().ToLower() = "cs"
      Select row).CopyToDataTable()

```

Regards,

---

<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:** [2024 年 10 月 4 日午後 2:21 UTC](https://forum.uipath.com/t/compare-datatable-values-with-array-using-linq/768196/7 "2024-10-04T14:21:11Z")

</div>

クローズされました: 2024 年 10 月 4 日午後 2:21 UTC

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