Foxtable(狐表)用户栏目专家坐堂 → 多表合并数据


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

主题:多表合并数据

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/3/20 19:03:00 [显示全部帖子]

Dim dt1 As DataTable = DataTables("汇总")
Dim dt2 As DataTable = DataTables("手术室")
Dim dt3 As DataTable = DataTables("外科")
For Each dr1 As DataRow In dt2.Select("")
    Dim dr2 As DataRow = dt1.Find("编码 = '" & dr1("编码") & "'")
    If dr2 Is Nothing Then dr2 = dt1.addnew
    For Each dc As DataCol In dt2.DataCols
        dr2(dc.Name) = dr1(dc.name)
    Next
    dr2("数量") = dt2.Compute("sum(数量)", "编码 = '" & dr1("编码") & "'") + dt3.Compute("sum(数量)", "编码 = '" & dr1("编码") & "'")
Next
For Each dr1 As DataRow In dt3.Select("")
    Dim dr2 As DataRow = dt1.Find("编码 = '" & dr1("编码") & "'")
    If dr2 Is Nothing Then dr2 = dt1.addnew
    For Each dc As DataCol In dt2.DataCols
        dr2(dc.Name) = dr1(dc.name)
    Next
    dr2("数量") = dt2.Compute("sum(数量)", "编码 = '" & dr1("编码") & "'") + dt3.Compute("sum(数量)", "编码 = '" & dr1("编码") & "'")
Next

 回到顶部