How can I implement this? Any activity would do but I prefer LINQ.
I have two datatables, Source_DT and Car_DT.
I want to remove the rows in Source_DT that have matched UID column from Car_DT. As you noticed there are duplicates on both datatables. If the duplicate row in Source_DT has another matching UID in Car_DT, it should also be removed. Also, there is duplicate row in Source_DT that does not have matching UID column in Car_DT, so it should remain on the Source_DT.
EXPECTED OUTPUT:
[EDITED]
Doesn’t need to be LINQ activity but it is preferable.
How can I implement this? Any activity would do but I prefer LINQ.
(From d1 In dtLeft.AsEnumerable
Group d1 By k=d1("UID").toString.Trim Into grp=Group
Let mcc = dtRight.AsEnumerable.Where(Function (d2) d2("UID").toString.Trim.Equals(k)).Count
Where Not (grp.Count = 1 And mcc > 0)
Where Not (grp.Count > 1 And mcc > 1)
Let skipper = Convert.ToInt32(grp.Count > 1 And mcc = 1)
From g In grp.Skip(skipper)
Order By dtLeft.Rows.IndexOf(g)
Select r=g).CopyToDataTable
And here is where we add items to our new Datatable →
(From kvp In dict_cars
Let rows = Source_DT.AsEnumerable.Where(Function(w) w("UID").Equals(kvp.Key)).Take(kvp.value).ToArray()
From row In rows
Select dt_result.Rows.Add(row.ItemArray.ToArray())).CopyToDataTable()
Different approaches help you become flexible.
Keep exploring solutions and you will become an Ace RPA Developer in no time.