Delete data row from data table

I am having a excel in format

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.

1 Like

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 (7.7 KB)

Regards…!!
Aksh

11 Likes

@aksh1yadav: Why not using RemoveDataRow instead of InvokeMethod?

3 Likes

SAMPLE1.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 ?

1 Like

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

2 Likes

@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 ?

1 Like

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

5 Likes

@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 (7.9 KB)

2 Likes

@Rahul_Raj

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

Regards,
Rahul

1 Like

DeleteRow.xaml (13.0 KB)

Try this.

Regards,
Rahul

3 Likes

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

1 Like

Hey @Sam

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

1 Like

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”. ?

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

Regards…!!
Aksh

1 Like

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

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

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

Hi there @1vivek12.

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

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

1 Like

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