Comparing 2 datables and deleting common rows in first datatable

Hi

I have 2 datatables i need to delete common rows in first datatable after comparing based on unique column in second datatable

Thanks
Likitha

@vinjam_likitha

Queue item fields are not exposed this way …you need to use it like this

dt1 = dt1.AsEnumerable.Where(function(p) dt2.AsEnumerable.Any(function(y) y("ColName1").ToString.Equals(p("Colname2").ToString))).CopyToDataTable

dt1 is your first table and dt2 is second

cheers

hi @vinjam_likitha

you can use a linq Expression in an assign activity:

dtUniqueData = DataTable1.AsEnumerable().Where(function(row) Not DataTable2.AsEnumerable().Select(function (r) r.Field(Of String)(“ColumnName”)).Any(function(x) x = row.Field(Of String)(“ColumnName”))).CopyToDataTable()

The brackets could be here and there but this should work.
Please replace ColumnName with your column name.

Thanks

Hi @vinjam_likitha

Follow the below workflow to delete the common columns in the datatable1.

- Assign -> Column1 = Datatable1.Columns.Cast(Of DataColumn)().Select(Function(c) c.ColumnName).ToList()
- Assign -> Column2 = Datatable2.Columns.Cast(Of DataColumn)().Select(Function(c) c.ColumnName).ToList()
- Assign -> CommonColumns = Column1.Intersect(Column2).ToList()

Note - Column1,Column2,Common Column variables are in List variable type

Use for each activity to iterate the common columns variable to get the each column which is column.
Use this column names in the delete column activity.
Check the below workflow for better understanding.
Excel_Demo.xaml (11.8 KB)

Hope it helps!!