Foxtable(狐表)用户栏目专家坐堂 → 复制代码的区别


  共有3940人关注过本帖树形打印复制链接

主题:复制代码的区别

帅哥哟,离线,有人找我吗?
wangglby
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:337 积分:3225 威望:0 精华:0 注册:2020/2/25 23:12:00
复制代码的区别  发帖心情 Post By: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


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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

 回到顶部