For Each Dr As DataRow In InvoiceDT.Rows
Dim DrResult As Array = PaymentInvoiceDT.Select("Amount='" & Dr("Amount").ToString() & "'")
If DrResult.Length > 0 Then
''some code
Else
InvoiceDT.Rows.remove(Dr)
End If
Next
It is giving error because when you changed something in datatable, its index get changed.
You won’t be able to do this in a For Each loop because when you remove something, the collection has changed and you can’t enumerate it anymore.
What you need is a reversed For loop.
This will still work even as you remove rows because the ones you’re not touching aren’t having their indexes changed and it doesn’t use an enumeration.