以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 如何做到快速新旧物料表对比  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92262)

--  作者:2900819580
--  发布时间:2016/10/30 16:33:00
--  [求助] 如何做到快速新旧物料表对比
如下代码,求高手优化


Dim Cn() As String = {"代码","全名","规格型号","名称"}
Dim tb As Table = Tables("物料表")
Dim tbdb As Table = Tables("物料导入_Tab物料对比")
Dim tbdr As Table = Tables("物料导入_Tab物料导入")
Dim i As Integer
Dim ii As Integer
\'Dim ci As Integer
Dim vstr As String
Dim vi As Integer

Dim tbstr As String
Dim drstr As String


DataTables("物料对比").StopRedraw
For i = 0 To tbdr.Rows.Count - 1
    drstr = tbdr.Rows(i)("代码") 
    For ii = 0 To tb.Rows.Count -1
        tbstr = tb.Rows(ii)("代码")
        If tbstr = drstr Then
            vi = 0
            For ci As Integer = 0 To cn.Length -1
                If tbdr.Rows(i)(cn(ci)) <> tb.Rows(ii)(cn(ci)) Then
                    vi = vi +1
                    vstr = vstr & "|" & cn(ci)\'tbdr.Rows(i)(cn(ci))
                End If
            Next
            Exit For
        Else
            vi = 1001
            vstr = Nothing
        End If
    Next
    
    If vi > 0 Then
        Dim r As Row = tbdb.AddNew
        For ci As Integer = 0 To cn.Length -1
            r(cn(ci)) = tbdr.Rows(i)(cn(ci))
        Next
        If vi = 1001 Then
            r("异类") = "新增"
        Else
            r("异类") = "修改"
        End If
        r("原因") = vstr
    End If
    \'i = 0
Next
DataTables("物料对比").ResumeRedraw
tbdb.AutoSizeCols

MessageBox.Show("全部对比完成","完成",MessageBoxButtons.OK,MessageBoxicon.Information)

--  作者:y2287958
--  发布时间:2016/10/30 16:34:00
--  

代码优化肯定是要上例子的

同时要有数据和详细说明

否则无从下手

[此贴子已经被作者于2016/10/30 16:35:30编辑过]

--  作者:2900819580
--  发布时间:2016/10/30 17:27:00
--  
就是两个表,表的结构是一致的,
有上万条数据,怎么样可以快速对比,将它们不一样的数据找出来。
增加在临时表上。