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
解决方法
您将无法在For Each循环中执行此操作,因为当您删除某些内容时,该集合已更改,您无法再枚举它.
你需要的是一个反向的For循环.
For i as Integer = Invoice.Rows.Count -1 to 0 Step -1 Dim DrResult As Array = PaymentInvoiceDT.Select("Amount='" & Invoice.Rows(i).("Amount").ToString() & "'") If DrResult.Length > 0 Then 'some code Else InvoiceDT.Rows.remove(InvoiceDT.Rows(i)) End If Next
即使在删除行时,这仍然有效,因为您没有触摸的行没有更改其索引并且不使用枚举.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。