遍历复制数据,数据条数对,但是数据内容是最后一行复制的多条……怎么修正按照样本表直接全部复制呢?
当前样本表:
此主题相关图片如下: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编辑过]