I have used LINQ to remove data/rows that exists in another datatable as below
(From d In Dt1.AsEnumerable()
Where Not Dt2.AsEnumerable.Any(Function (x) x(“ID”).toString.Equals(d(“ID”).ToString))
Select d).CopyToDataTable
The problem is sometimes all data in Dt1 exists in Dt2 so output is 0 that throws error. Please assist how to handle that exception
You can use a try-catch block to handle the exception. Try the following code:
Try
(From d In Dt1.AsEnumerable()
Where Not Dt2.AsEnumerable.Any(Function (x) x(“ID”).toString.Equals(d(“ID”).ToString))
Select d).CopyToDataTable
Catch ex As Exception
'Do something with the exception here
End Try