Foxtable(狐表)用户栏目专家坐堂 → 关于填充


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

主题:关于填充

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/27 14:20:00 [显示全部帖子]

ExcludeExistValue 设置成true,可以排除重复值。

 

For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim dr2 As DataRow = DataTables("表B").AddNew()
    For Each dc As DataCol In DataTables("表A").DataCols
        If DataTables("表B").DataCols.Contains(dc.name) Then
            dr2(dc.Name) = dr1(dc.name)
        End If
    Next
Next


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/27 15:22:00 [显示全部帖子]

Dim ary1() As String = {"产品1", "产品2"}
Dim ary2() As String = {"分类1", "分类2"}
For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim dr2 As DataRow = DataTables("表B").AddNew()
    For Each dc As DataCol In DataTables("表A").DataCols
        If DataTables("表B").DataCols.Contains(dc.name) Then
            dr2(dc.Name) = dr1(dc.name)
        End If
    Next
    For i As Integer = 0 To ary1.length-1
        dr2(ary2(i)) = dr1(ary1(i))
    next
Next

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/27 16:07:00 [显示全部帖子]

Dim ary1() As String = {"分类1", "产品1"}
Dim ary2() As String = {"分类2", "产品2"}
For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim dr2 As DataRow = DataTables("表B").AddNew()
    For Each dc As DataCol In DataTables("表A").DataCols
        If DataTables("表B").DataCols.Contains(dc.name) Then
            dr2(dc.Name) = dr1(dc.name)
        End If
    Next
    For i As Integer = 0 To ary1.length-1
        dr2(ary2(i)) = dr1(ary1(i))
    next
Next
[此贴子已经被作者于2017/10/27 16:07:18编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/10/27 17:24:00 [显示全部帖子]

Dim ary1() As String = {"分类1", "产品1"}
Dim ary2() As String = {"分类2", "产品2"}

For Each dr1 As DataRow In DataTables("表A").Select("")
    Dim filter As String = "1=1"
    For Each dc As DataCol In DataTables("表A").DataCols
        If DataTables("表B").DataCols.Contains(dc.name) Then
            If dr1.IsNull(dc.name) Then
                filter &= " and " & dc.name & " is null"
            Else
                filter &= " and " & dc.name & " = '" & dr1(dc.name) & "'"
            End If
        End If
    Next
    For i As Integer = 0 To ary1.length-1
        If dr1.IsNull(ary1(i)) Then
            filter &= " and " & ary2(i) & " is null"
        Else
            filter &= " and " & ary2(i) & " = '" & dr1(ary1(i)) & "'"
        End If
    Next
    Dim dr2 As DataRow = DataTables("表B").find(filter)
    If dr2 Is Nothing Then
        dr2 = DataTables("表B").addnew
        For Each dc As DataCol In DataTables("表A").DataCols
            If DataTables("表B").DataCols.Contains(dc.name) Then
                dr2(dc.Name) = dr1(dc.name)
            End If
        Next
        For i As Integer = 0 To ary1.length-1
            dr2(ary2(i)) = dr1(ary1(i))
        Next
    end if
Next


 回到顶部