Foxtable(狐表)用户栏目专家坐堂 → 遍历复制数据,数据条数对,但是数据内容是最后一行复制的多条……怎么修正按照样本表直接全部复制呢?


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

主题:遍历复制数据,数据条数对,但是数据内容是最后一行复制的多条……怎么修正按照样本表直接全部复制呢?

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
遍历复制数据,数据条数对,但是数据内容是最后一行复制的多条……怎么修正按照样本表直接全部复制呢?  发帖心情 Post By:2022/12/8 10:53:00 [显示全部帖子]

遍历复制数据,数据条数对,但是数据内容是最后一行复制的多条……怎么修正按照样本表直接全部复制呢?

当前样本表:

 
图片点击可在新窗口打开查看此主题相关图片如下:1.png
图片点击可在新窗口打开查看

当前代码运行后得到的数据表:

 
图片点击可在新窗口打开查看此主题相关图片如下:2.png
图片点击可在新窗口打开查看

 

当前代码:

Dim cmd As New SQLC ommand
cmd.Conn ectio nName = "主数据源"
cmd.CommandText = "Sel ect * From 登记台账"
Dim dt11 As DataTable = cmd.ExecuteReader()
cmd.CommandText = "delet e from {登记台账汇总表}"
cmd.ExecuteNonQuery()
cmd.CommandText = "Selec t * From 登记台账汇总表"
Dim dt12 As DataTable = cmd.ExecuteReader(True)
Dim Products As List(Of String)
Products =  dt11.GetValues("guid")
For Each Product As String In Products
    Output.Show(Product)
    Dim dr1 As DataRow = dt12.AddNew
    For Each dc As DataCol In dt11.DataCols
        Output.Show(dc.Name)
        For Each dr As DataRow In dt11.datarows
            If dr.isnull(dc.Name)=False
                dr1(dc.Name) = dr(dc.Name)
            End If
        Next
    Next
    dt12.save()
Next

 

 

写法二:【运行后还是一样的效果】

Dim cmd As New SQ LCommand
cmd.Connecti
cmd.CommandText = "Sele ct * From 日常监督检查登记台账"
Dim dt11 As DataTable = cmd.ExecuteReader()
cmd.CommandText = "dele te from {日常监督检查登记台账汇总表}"
cmd.ExecuteNonQuery()
cmd.CommandText = "Sele ct * From 日常监督检查登记台账汇总表"
Dim dt12 As DataTable = cmd.ExecuteReader(True)
Dim Products As List(Of String)
Products =  dt11.GetValues("guid")
For Each Product As String In Products
    Output.Show(Product)
    Dim dr1 As DataRow = dt12.AddNew
    For Each dr As DataRow In dt11.Se lect("guid=‘“& Product &"'")
        For Each dc As DataCol In dt11.DataCols
            Output.Show(dc.Name)
            If dr.isnull(dc.Name)=False
                dr1(dc.Name) = dr(dc.Name)
            End If
        Next
    Next
    dt12.save()
Next

[此贴子已经被作者于2022/12/8 10:57:32编辑过]

 回到顶部