# Delete data row from data table

**URL:** <https://forum.uipath.com/t/delete-data-row-from-data-table/4498>\
**Category:** Help\
**Tags:** datatable, excel, system, activities\
**Created:** [May 10, 2017, 9:35am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498 "2017-05-10T09:35:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgangrade7](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mgangrade7](https://forum.uipath.com/u/mgangrade7)\
**Post date:** [May 10, 2017, 9:35am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/1 "2017-05-10T09:35:28Z")

</div>

I am having a excel in format

 ![](https://global.discourse-cdn.com/uipath/original/2X/0/0bb580ac2e07ad1f28b07340994a16db097ed5d0.PNG)

Now I want to delete all the row where Status=“PV”.

Please suggest a solution. I want to perform this action using one database table only.

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [May 10, 2017, 10:22am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/2 "2017-05-10T10:22:20Z")

</div>

Hey @mgangrade7

To delete rows from datatable, you could use the logic like this:

1. Use the select function on the datatable to filter the rows that match your condition and this will return an array of Datarows.
2. Then use a for each loop and remove each row from the Array of Datarows using **datatable.Rows.Remove(row)**;

For Your Reference find the attached sample solution: [Delete\_Data\_Row\_From\_Datatable.zip](https://global.discourse-cdn.com/uipath/original/2X/b/b270d7e47d28b9db6798a7b0c4999f2851e0f71f.zip) (7.7 KB)

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![badita](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/badita/32/6_2.png) [@badita](https://forum.uipath.com/u/badita)\
**Post date:** [May 10, 2017, 10:49am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/3 "2017-05-10T10:49:48Z")

</div>

@aksh1yadav: Why not using `RemoveDataRow` instead of `InvokeMethod`?

---

<div class="post-metadata">

**Author:** ![Rahul\_Raj](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@Rahul\_Raj](https://forum.uipath.com/u/Rahul_Raj)\
**Post date:** [June 5, 2017, 8:16am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/4 "2017-06-05T08:16:25Z")

</div>

[SAMPLE1.xlsx](https://global.discourse-cdn.com/uipath/original/2X/8/8b9dcb92c657dcb1c9eb5cf28db8fbb3dc3f76fb.xlsx) (8.6 KB)

@aksh1yadav How to remove if complete row is blank row.For Example i am attaching xlsx file .In this xlsx file 4th row is completly blank row. how to remove this row ?

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [June 5, 2017, 8:41am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/5 "2017-06-05T08:41:06Z")

</div>

Just Use the If condition to check those required columns are blank or not then if they are then use Remove data row activity .

---

<div class="post-metadata">

**Author:** ![Rahul\_Raj](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@Rahul\_Raj](https://forum.uipath.com/u/Rahul_Raj)\
**Post date:** [June 5, 2017, 9:05am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/6 "2017-06-05T09:05:00Z")

</div>

@aksh1yadav In your attached Delete\_Data\_Row\_From\_Datatable.zip in assign field you are assiging data.Select(“[Status]=‘PV’”).where i need to use if condition,can you please share the xaml file for this ?

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [June 5, 2017, 9:45am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/7 "2017-06-05T09:45:28Z")

</div>

> [@Rahul\_Raj](#):
>
> data.Select(“[Status]=‘PV’”).

this statement returning the rows which are having status ‘PV’. so you have to modify it something like this for your requirement

**DataTable.Select(“[COLUMN 1]=‘’ OR [COLUMN 2]=‘’”)**

and if null values you have then you can use like this:

**DataTable.Select(“[COLUMN NAME] is null”);**

and then you can easily inside for each loop ,can use **Remove data row** activity.

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![Rahul\_Raj](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@Rahul\_Raj](https://forum.uipath.com/u/Rahul_Raj)\
**Post date:** [June 5, 2017, 11:17am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/8 "2017-06-05T11:17:16Z")

</div>

@aksh1yadav when i am providing properties for Remove data row Activity, i am getting an error and not able to resovle this one.For reference i am attaching my xaml file.Can you please help me regarding this issue so that i can delete my blank row from xls file.[DeleteBlankrow.zip](https://global.discourse-cdn.com/uipath/original/2X/d/d59f80bd24984877eac1885ee3ffa669ac0fbc8f.zip) (7.9 KB)

---

<div class="post-metadata">

**Author:** ![Rahul](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rahul/32/2028_2.png) [@Rahul](https://forum.uipath.com/u/Rahul)\
**Post date:** [June 6, 2017, 5:30am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/9 "2017-06-06T05:30:05Z")

</div>

@Rahul_Raj

Use “Item” in row field of remove data row activity.

Regards,  
Rahul

---

<div class="post-metadata">

**Author:** ![Rahul](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rahul/32/2028_2.png) [@Rahul](https://forum.uipath.com/u/Rahul)\
**Post date:** [June 6, 2017, 5:44am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/10 "2017-06-06T05:44:04Z")

</div>

[DeleteRow.xaml](https://global.discourse-cdn.com/uipath/original/2X/4/4b92198825a8e50b04d6a57e45a854796d58d43b.xaml) (13.0 KB)

Try this.

Regards,  
Rahul

---

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.uipath.com/u/Sam)\
**Post date:** [October 25, 2017, 4:53am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/11 "2017-10-25T04:53:56Z")

</div>

Suppose if i want to delete a row in which a column contains a particular string…How to do that…?

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [October 26, 2017, 4:44am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/12 "2017-10-26T04:44:57Z")

</div>

Hey @Sam

> [@Sam](#):
>
> Suppose if i want to delete a row in which a column contains a particular string…How to do that…

You have yo use similar Datatable.select() with your column name and string then it will return an array of DataRow. then you can use Foreach loop and inside Remove data row activity pass that filtered row item.

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![Sam](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Sam](https://forum.uipath.com/u/Sam)\
**Post date:** [October 26, 2017, 6:33am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/13 "2017-10-26T06:33:19Z")

</div>

ok i got that.  
but Suppose in a datatable i want to remove those rows in which a column contains a particular word “Forward”.  
for example- my string is “Forward: UiPath v/s blueprism”. I want to remove all those rows which contains this word “Forword”. ?

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [October 26, 2017, 6:39am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/14 "2017-10-26T06:39:18Z")

</div>

> [@Sam](#):
>
> for example- my string is “Forward: UiPath v/s blueprism”. I want to remove all those rows which contains this word “Forword”. ?

`**Datatable.Select("ColName LIKE '*Forward:*'")**` to filter those rows.

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![1vivek12](https://avatars.discourse-cdn.com/v4/letter/1/ea5d25/32.png) [@1vivek12](https://forum.uipath.com/u/1vivek12)\
**Post date:** [November 17, 2017, 11:25am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/15 "2017-11-17T11:25:49Z")

</div>

> [@Rahul\_Raj](#):
>
> dition,can you pl

Hi rahul like here you have put PV but i need to delete row which are not equal to a string variable how should i delete row then as variable value keep on changing

---

<div class="post-metadata">

**Author:** ![1vivek12](https://avatars.discourse-cdn.com/v4/letter/1/ea5d25/32.png) [@1vivek12](https://forum.uipath.com/u/1vivek12)\
**Post date:** [November 17, 2017, 11:26am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/16 "2017-11-17T11:26:26Z")

</div>

Hi aksh1yadav like here you have put PV but i need to delete row which are not equal to a string variable how should i delete row then as variable value keep on changing

---

<div class="post-metadata">

**Author:** ![1vivek12](https://avatars.discourse-cdn.com/v4/letter/1/ea5d25/32.png) [@1vivek12](https://forum.uipath.com/u/1vivek12)\
**Post date:** [November 17, 2017, 11:30am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/17 "2017-11-17T11:30:47Z")

</div>

My column name is ENODEB and my variable is Current\_SiteID. so in a data datable if row is not equal current\_siteid ,then delete row

---

<div class="post-metadata">

**Author:** ![Mr\_JDavey](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mr_jdavey/32/1001_2.png) [@Mr\_JDavey](https://forum.uipath.com/u/Mr_JDavey)\
**Post date:** [November 17, 2017, 11:35am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/18 "2017-11-17T11:35:25Z")

</div>

Hi there @1vivek12.

> [@1vivek12](#):
>
> i need to delete row which are not equal to a string variable how should i delete row then as variable value keep on changing

> [@1vivek12](#):
>
> My column name is ENODEB and my variable is Current\_SiteID. so in a data datable if row is not equal current\_siteid ,then delete row

You can do the following:

`dtMyDataTable = dtMyDataTable.AsEnumerable.Where(Function (x) x.Item("ENODEB").ToString.Trim.ToLower.Equals(current_siteid.Trim.ToLower) = True).CopyToDataTable`

This will return a DataTable where all rows meet your criteria (‘ENODEB’ column = current\_siteid).

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![1vivek12](https://avatars.discourse-cdn.com/v4/letter/1/ea5d25/32.png) [@1vivek12](https://forum.uipath.com/u/1vivek12)\
**Post date:** [November 17, 2017, 11:44am UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/19 "2017-11-17T11:44:35Z")

</div>

> [@Mr\_JDavey](#):
>
> .AsEnumerable.Where(Function (x) x.Item(“ENODEB”).ToString.Trim.ToLower.Equals(current\_siteid.Trim.ToLower) = True).CopyToDataTable

Thanks a lot Josh worked like magic.no need to delete row now.Thanks! and will help with other things as well.

---

<div class="post-metadata">

**Author:** ![1vivek12](https://avatars.discourse-cdn.com/v4/letter/1/ea5d25/32.png) [@1vivek12](https://forum.uipath.com/u/1vivek12)\
**Post date:** [November 17, 2017, 12:15pm UTC](https://forum.uipath.com/t/delete-data-row-from-data-table/4498/20 "2017-11-17T12:15:09Z")

</div>

> [@Mr\_JDavey](#):
>
> AsEnumerable

Hey @Mr_JDavey i need to remove duplicate row based on rows in column Sector\_ID. can you help with that too!

[Next page](https://forum.uipath.com/t/delete-data-row-from-data-table/4498.md?page=2)
