以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  复制代码的区别  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170860)

--  作者:wangglby
--  发布时间:2021/8/9 22:05:00
--  复制代码的区别
   这段代码把数据从 表A复制到A1
 For Each dr1 As DataRow In DataTables("表A").datarows
        Dim dr2 As DataRow = DataTables("表A1"). sqlfind("编码=\'" & dr1("编码") & "\'")
        If dr2 Is Nothing Then
           dr2 =  DataTables("表A1").AddNew()
            For Each dc As DataCol In DataTables("表A").DataCols
               If  DataTables("表A1").DataCols.Contains(dc.name)  Then
                    If dc.Expression = "" Then  
                    If dr1.IsNull(dc.name) =False Then 
                        dr2(dc.Name) = dr1(dc.name)

End If
End If
 End If
End If
   Next
NEXT


下面 这段代码把选中的数据从表A1复制到A,我发现 第一段效率明显比第二段代码高,请问第二段应该怎么加速?

Dim t As Table = Tables("表A1")

Dim a1 As Integer
For i As Integer = t.TopPosition To t.BottomPosition
Dim dr2 As DataRow  =  DataTables("表A").AddNew()
    For Each dc As DataCol In DataTables("表A1").datacols        
    If  DataTables("表A").DataCols.Contains(dc.name)   Then   
    If dc.Expression = "" Then
   If t.Rows(i).IsNull(dc.name) =False Then

    dr2(dc.Name) = t.Rows(i)(dc.name)



  End If
    End If
End If
 Next
        
Next


--  作者:有点蓝
--  发布时间:2021/8/9 22:40:00
--  
看看:http://www.foxtable.com/webhelp/topics/2225.htm

试试

Dim t As Table = Tables("表A1")
Dim t1 As Table = Tables("表A")
Dim lst As new List(of String)
For Each dc As DataCol In DataTables("表A1").datacols
    If  DataTables("表A").DataCols.Contains(dc.name) AndAlso  dc.Expression = ""  Then
        lst.add(dc.name)
    End If
Next
t1.StopRedraw
Dim r,r1 As Row
For i As Integer = t.TopPosition To t.BottomPosition
    r = t1.AddNew()
    r1 = t.Rows(i)
    For Each s As String In lst
        r(s) =  r1(s)
    Next
Next
t1.ResumeRedraw