以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  删除重复行  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=180296)

--  作者:zhuxinhui
--  发布时间:2022/10/12 23:14:00
--  删除重复行
\'Dim i As Integer
\'For i = DataTables("BOM清单").DataRows.Count - 1 To 0 Step - 1
\'    Dim dr As DataRow = DataTables("BOM清单").DataRows(i) 
\'        Dim dr2 As DataRow = DataTables("BOM清单").SQLFind("母件编码 = \'" & dr("母件编码") & "\' And 子件编码 = \'" & dr("子件编码") & "\' and _Identify > " & dr("_Identify"))
\'        If dr2 IsNot Nothing Then
\'            dr2.Delete
\'        End If 
\'Next

上面的代码用来删除重复行不起作用,不知是什么回事,不知是不是有超三行重复时不起作用

--  作者:有点蓝
--  发布时间:2022/10/13 8:47:00
--  
Dim i As Integer
Dim dr1 As DataRow = DataTables("BOM清单").DataRows(DataTables("BOM清单").DataRows.Count - 1)
Dim dr As DataRow
For i = DataTables("BOM清单").DataRows.Count - 2 To 0 Step - 1
    dr = DataTables("BOM清单").DataRows(i)
    If dr("母件编码") = dr1("母件编码") AndAlso dr("子件编码") = dr1("子件编码") Then
        dr.delete
    Else
        DataTables("BOM清单").save
        DataTables("BOM清单").SQLDeleteFor("母件编码 = \'" & dr1("母件编码") & "\' And 子件编码 = \'" & dr1("子件编码") & "\' and _Identify <> " & dr1("_Identify"))
        dr1 = dr
    End If 
    
Next
DataTables("BOM清单").save
DataTables("BOM清单").SQLDeleteFor("母件编码 = \'" & dr1("母件编码") & "\' And 子件编码 = \'" & dr1("子件编码") & "\' and _Identify <> " & dr1("_Identify"))