# Linq

**URL:** <https://forum.uipath.com/t/linq/406030>\
**Category:** Activities\
**Tags:** datatable, how-to-delete-empty-row-and-rows-contain, question, studio, system, activities\
**Created:** [March 10, 2022, 12:30pm UTC](https://forum.uipath.com/t/linq/406030 "2022-03-10T12:30:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shreesha.bhat4](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shreesha.bhat4/32/176817_2.png) [@shreesha.bhat4](https://forum.uipath.com/u/shreesha.bhat4)\
**Post date:** [March 10, 2022, 12:30pm UTC](https://forum.uipath.com/t/linq/406030/1 "2022-03-10T12:30:04Z")

</div>

How to delete empty rows and rows containing particular character in datatable using a single Linq command?

---

<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:** [March 10, 2022, 12:36pm UTC](https://forum.uipath.com/t/linq/406030/2 "2022-03-10T12:36:03Z")

</div>

Hi @shreesha.bhat4 ,

This solves the first half of your query

```auto
Dt.AsEnumerable.Where(Function(w) Not(IsNothing(w(0)) OrElse String.IsNullOrEmpty(w(0).ToString))).CopyToDataTable()

```

For the second half, could you tell us whether this character is present in any of the columns, or in just few given columns or the entire dataset?

Lets say the character is “\*” and can be present anywhere in the dataset, then this will work:

```auto
Dt.AsEnumerable.Where(Function(w) Not(IsNothing(w(0)) OrElse String.IsNullOrEmpty(w(0).ToString) OrElse w.ItemArray.Contains("*"))).CopyToDataTable()

```

**Kind Regards,  
Ashwin A.K**

---

<div class="post-metadata">

**Author:** ![Sudharsan\_Ka](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sudharsan_ka/32/459826_2.png) [@Sudharsan\_Ka](https://forum.uipath.com/u/Sudharsan_Ka)\
**Post date:** [March 10, 2022, 12:36pm UTC](https://forum.uipath.com/t/linq/406030/3 "2022-03-10T12:36:05Z")

</div>

HI @shreesha.bhat4

For deleting empty rows in datatable refer this link

[![](https://global.discourse-cdn.com/uipath/original/4X/f/9/8/f98b40862499d9f54edfff7b90a661a68c75c49d.jpeg "LINQ | Remove Empty Row From Datatable | LINQ Uipath Tutorials | Coderslobby") ](https://www.youtube.com/watch?v=brsbXixmKOA)

Regards  
Sudharsan

---

<div class="post-metadata">

**Author:** ![Gokul001](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gokul001/32/462734_2.png) [@Gokul001](https://forum.uipath.com/u/Gokul001)\
**Post date:** [March 10, 2022, 12:48pm UTC](https://forum.uipath.com/t/linq/406030/4 "2022-03-10T12:48:53Z")

</div>

Hi @shreesha.bhat4

Try this expression

```auto
DtMaster.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).CopyToDataTable()

```

Regards  
Gokul

---

<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:** [March 10, 2022, 3:46pm UTC](https://forum.uipath.com/t/linq/406030/5 "2022-03-10T15:46:30Z")

</div>

> [@shreesha.bhat4](#):
>
> How to delete empty rows and rows

we assume check for all cols

> [@shreesha.bhat4](#):
>
> rows containing particular character in datatable

here is unclear if all or a particular column is to check

Empty All cols, All cols check for char:

```auto
(From d in dtData.AsEnumerable
Where Not d.ItemArray.Any(Function (x) isNothing(x) OrElse String.IsNullorEmpty(x.toString.Trim))
Where Not d.ItemArray.Any(Function (x) x.toString.Contains("YourCheckString")
Select r=d).CopyToDataTable

```

Empty All cols, single cols check for char:

```auto
(From d in dtData.AsEnumerable
Where Not d.ItemArray.Any(Function (x) isNothing(x) OrElse String.IsNullorEmpty(x.toString.Trim))
Where Not dYourColNameOrIndex).toString.Contains("YourCheckString")
Select r=d).CopyToDataTable

```

---

<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:** [March 13, 2022, 3:47pm UTC](https://forum.uipath.com/t/linq/406030/6 "2022-03-13T15:47:27Z")

</div>

Closed on March 13, 2022, 3:47pm UTC

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