麻烦老师帮忙看看 从一个表中遍历数据写入另外一个表 能够输出值 但是遍历后新表对应的数值部分没有值
当前代码如下:红色部分没有写入正确的值……
Dim cmd As New SQLCommand
cmd.Conne ctio nName = "主数据源"
Dim dt As DataTable
cmd.CommandText = "SEL ECT * From {费用登记}"
dt = cmd.ExecuteReader()
Dim dt2 As DataTable
cmd.CommandT ext = "SEL ECT * From {人员关系}"
dt2 = cmd.ExecuteReader()
Dim dt1 As DataTable
cmd.CommandText = "del ete From {费用登记汇总}"
cmd.ExecuteReader()
cmd.CommandText = "SE LECT * From {费用登记汇总}"
dt1 = cmd.ExecuteReader(True)
Dim Products As List(Of String())
Products = dt.GetValues("单位名称|日期|姓名")
For Each Product As String() In Products
Dim drs As List(of DataRow) =dt.SQ LSe lect("单位名称='" & Product(0) & "' and 姓名='" & Product(2) & "'") '可以找到对应样本数据
'Output.Show(Product(0))
'Output.Show(Product(2))
Dim dr1 As DataRow = dt1.AddNew
For Each dc As DataCol In dt.DataCols
For Each dr As DataRow In drs
'output.show(dr(dc.Name)) 输出能够得到对应的数值
dr1("guid")=guid.newguid.tostring()
dr1("单位名称")=Product(0)
dr1("姓名")=Product(2)
dr1("日期")=Product(1)
Dim dr2 As DataRow =dt2.SQ LF ind("姓名='"& Product(2) &"'")
If dr2 IsNot Nothing Then
dr1("关联人")=dr2("关系人姓名")
dr1("关联关系")=dr2("与本人关系")
End If
output.show(dr("实发工资")) 输出有值
dr1("实发工资")=dr("实发工资")
dr1("工资")=dr("工资")
dr1("加班费")=dr("加班费")
dr1("补贴")=dr("补贴")
dr1("津贴")=dr("津贴")
dr1("外勤补助")=dr("外勤补助")
dr1("备用1")=dr("备用1")
dr1("备用2")=dr("备用2")
dr1("备用3")=dr("备用3")
dr1("备用4")=dr("备用4")
dr1("备用5")=dr("备用5")
dr1("医疗保险")=dr("医疗保险")
dr1("电话费")=dr("电话费")
dr1("其它费用")=dr("其它费用")
dr1("备用字段")=dr("备用字段")
dr1("签名")=dr("签名")
dr1("目标考核奖")=dr("目标考核奖")
以上红色部分注释 然后用这个 得到的效果一样 'dr1(dc.Name) = dr(dc.Name)
Next
Next
dt1.save
Next