No, there's no chance to remove data without using
For...Next
loop.
Note: you're using
For...Next
loop 3 times. You can short it to one loop only. How? Join tables by
Name
field to get common records for both tables, then remove it from
dt1
.
Dim rows_to_remove = From a In dt1.AsEnumerable() Join b In dt2.AsEnumerable() On a.Field(Of String)("Name") Equals b.Field(Of String)("Name")
Select a
You can use Linq
Except[
^] method too:
Dim rows_to_remove = dt2.AsEnumerable.Except(dt1.AsEnumerable())
But! I'd do that on server side by using Transact SQL. See:
DELETE (Transact-SQL) | Microsoft Docs[
^]
DELETE
FROM Table1
WHERE FieldName1 IN (SELECT FieldName1 FROM Table2)