我在下面寫的代碼將正確地循環迭代循環。它根據條件測試正確的行,將其添加到「輔助」DataTable中,並按照它的要求從「主」中移除。然而,在該循環的第二次迭代我收到以下錯誤:在Visual Basic中通過DataTable循環的錯誤
Collection was modified; enumeration operation might not execute.
這裏是我使用
For Each row As DataRow In tblAgencyEdInfo.Rows
Dim rDate As DateTime = row.Item("ExpirationDate")
If rDate < DateTime.Now Then
tblExpEdInfo.ImportRow(row)
tblAgencyEdInfo.Rows.Remove(row)
End If
Next row