To delete rows from datatable, you could use the logic like this:
Use the select function on the datatable to filter the rows that match your condition and this will return an array of Datarows.
Then use a for each loop and remove each row from the Array of Datarows using
For Your Reference find the attached sample solution:
Delete_Data_Row_From_Datatable.zip (7.7 KB)
@aksh1yadav: Why not using
RemoveDataRow instead of
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 ?
Just Use the If condition to check those required columns are blank or not then if they are then use Remove data row activity .
@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 ?
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.
@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)
Use “Item” in row field of remove data row activity.
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.
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.
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
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
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 a lot Josh worked like magic.no need to delete row now.Thanks! and will help with other things as well.
@Mr_JDavey i need to remove duplicate row based on rows in column Sector_ID. can you help with that too!
You can do the following:
Assign – dtMyDataTable = dtMyDataTable.AsEnumerable.GroupBy(Function (x) x.Item("Sector_ID")).Select(Function (i) i.First).CopyToDataTable
This will return the first rows with unique values in the column “Sector_ID”.