以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]重复值查找并导到另一同结构表时太缓慢  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=74621)

--  作者:xiangwei_zeng
--  发布时间:2015/9/15 16:31:00
--  [求助]重复值查找并导到另一同结构表时太缓慢

Dim i As Integer
For i  = 0 To DataTables("零件工艺").DataRows.Count-1 Step 1
    Dim dr As DataRow = DataTables("零件工艺").DataRows(i)
    Dim dr2 As DataRow = DataTables("零件工艺").Find("图号=\'" & dr("图号") & "\' and 计件工序=\'" & dr("计件工序") & "\' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        Dim dr3 As DataRow = DataTables("重复工序零件工艺").AddNew
        For Each dr4 As DataCol In DataTables("重复工序零件工艺").DataCols
            dr3(dr4.Name) = dr(dr4.Name)
        Next
    End If
Next

上述代码执行卡死,数据只2万行多一点,是哪儿有问题呢?


图片点击可在新窗口打开查看此主题相关图片如下:零件工序.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2015/9/15 16:31:47编辑过]

--  作者:Hyphen
--  发布时间:2015/9/15 18:06:00
--  

使用以下sql查找重复记录,一个循环赋值即可,查询结果放到sql查询器看看

Sel ect a.* FROM {零件工艺} As a  inner join (Sel ect 图号,计件工序  FROM {零件工艺} GROUP BY 图号,计件工序  HAVING Count(*)>1  ) As Tmp ON  a.图号=Tmp.图号  And a.计件工序= Tmp.计件工序


--  作者:Hyphen
--  发布时间:2015/9/15 18:08:00
--  
关于效率问题参考http://www.foxtable.com/help/topics/2225.htm
--  作者:xiangwei_zeng
--  发布时间:2015/9/15 18:14:00
--  

谢谢,帮助内容太多,有时找都要好半天,有时还想不透,所有就提问了。


--  作者:大红袍
--  发布时间:2015/9/15 19:23:00
--  

mark 查询与赋值

 

Dim tdic As new Dictionary(of DataRow, DataRow)
Dim tls As new List(of DataRow)

Dim i As Integer
For i  = 0 To DataTables("零件工艺").DataRows.Count-1
    Dim dr As DataRow = DataTables("零件工艺").DataRows(i)
    Dim dr2 As DataRow = DataTables("零件工艺").Find("图号=\'" & dr("图号") & "\' and 计件工序=\'" & dr("计件工序") & "\' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        tdic.add(dr2, dr)
    Else
        tls.Add(dr)
    End If
Next

For Each key As DataRow In tdic.Keys
    For Each dc As DataCol In DataTables("重复工序零件工艺").DataCols
        key(dc.Name) = tdic(key)(dc.Name)
    Next
Next
For Each dr As DataRow In tls
   
    Dim ndr As DataRow = DataTables("重复工序零件工艺").AddNew
    For Each dc As DataCol In DataTables("重复工序零件工艺").DataCols
        ndr(dc.Name) = dr(dc.Name)
    Next
   
Next