如何在 VB.NET 中将 CopyToDataTable 与两个数据表查询一起使用

问题描述 投票:0回答:0

如何在 VB.NET 中将 CopyToDataTable 与两个数据表查询一起使用?。 员工信息下不应出现“性别”列,如我标记为红色警告的标志,性别信息下不应出现“雇员 ID”列和“全名”列,如我标记为红色警告的标志。

我的代码有问题吗?

谢谢

Private Sub GeneratePayslip()
        Dim dt As New DataTable()
        report.Clear()
        Dim query1 = "SELECT tblemployee.Empid AS [EMPLOYEE ID] ,tblemployee.Name AS [FULL NAME] FROM tblabsent INNER JOIN tblemployee ON tblabsent.EMPID = tblemployee.EMPID"
        Using adapter1 As New OleDbDataAdapter(query1, con)
            adapter1.Fill(dt)
        End Using
        Dim query2 = "SELECT tblemployee.GENDER FROM tblabsent INNER JOIN tblemployee ON tblabsent.EMPID = tblemployee.EMPID"
        Using adapter2 As New OleDbDataAdapter(query2, con)
            adapter2.Fill(dt)
        End Using
        For Each row As DataRow In dt.Rows
            report.AddHorizontalRule()
            report.AddLineBreak()
  report.AddLineBreak()
            report.AddHorizontalRule()
            report.AddLineBreak()
            report.AddString("<h3>Employee Information</h3>")
            Dim table1 = {row}.CopyToDataTable()
            report.AddDataTable(table1)
            report.AddLineBreak()
            report.AddHorizontalRule()
            report.AddLineBreak()
            report.AddString("<h3>Gender Information</h3>")
            table1.Columns.Clear()
            Dim table2 = {row}.CopyToDataTable()
            report.AddDataTable(table2)
            report.NewPage()
        Next row
    End Sub

vb.net datatable row
© www.soinside.com 2019 - 2024. All rights reserved.