Delete data row from data table

datatable
excel
activities

#1

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.


Delete the row if column has "0"
Hot key down arrow
#2

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


Delete datarow in datatable
Remove empty row in the excel
#3

@aksh1yadav: Why not using RemoveDataRow instead of InvokeMethod?


#4

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 ?


#5

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


#6

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


#7

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


To select Column with null values
#8

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


#9

@Rahul_Raj

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

Regards,
Rahul


#10

DeleteRow.xaml (13.0 KB)

Try this.

Regards,
Rahul


#11

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


#12

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


#13

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


#14

Datatable.Select(“ColName LIKE ‘Forward:’”) to filter those rows.

Regards…!!
Aksh


#15

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


#16

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


#17

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


#18

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


#19

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


#20

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