删除表中的重复值,用第一段代码可以实现要求,但是给出错误的提示,而用第二段代码则顺利通过。问题时是为什么运行第一段代码会出错呢?请各位老师指教,谢谢!!
运行第一段代码出错
For Each dr As DataRow In DataTables("清点明细").DataRows
If dr.IsNull("编号") = False Then
Dim dr2 As DataRow = DataTables("清点明细").Find("清点日期 = '" & rq & "' And 编号 = '" & dr("编号") & "' and _Identify > " & dr("_Identify"))
If dr2 IsNot Nothing Then
dr2.Delete
End If
End If
Next
此主题相关图片如下:捕获.png

运行第二段代码顺利通过
Dim i As Integer
For i = DataTables("清点明细").DataRows.Count-1 To 0 Step -1
Dim dr As DataRow = DataTables("清点明细").DataRows(i)
Dim dr2 As DataRow = DataTables("清点明细").Find("清点日期 = '" & rq & "' And 编号 = '" & dr("编号") & "' and _Identify > " & dr("_Identify"))
If dr2 IsNot Nothing Then
dr2.Delete
End If
Next
[此贴子已经被作者于2017/12/5 13:57:46编辑过]