将数据表导出到水晶报告

时间:2015-01-20 05:43:22

标签: vb.net datatable crystal-reports xsd

我创建了一个数据表(.xsd),它对应于我在代码隐藏中编码的数据表。

Figure 1

Protected Sub btnDproceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDproceed.Click


    '---> ASSUME THAT I CODES FOR THE FIRST FOUR COLUMNS OF DATATABLE IS MADE HERE
    '---> CREATE DYNAMIC COLUMNS OF SCORES
    cn.Open()
    '---> SQL COMMAND HERE THAT GET TOP 5 DATA FROM DATABASE USED TO GENERATE 5 ADDITIONAL COLUMNS IN dt
    rs = cmd.ExecuteReader
    Do While rs.Read
        Dim gwno As String = rs.Item("GWNO").ToString
        If gwno.Length = 1 Then
            gwno = "0" & gwno
        End If
        Dim vHeader As String = "LES" & gwno & "_" & rs.Item("GWTYPE")
        If Not dt.Columns.Contains(vHeader) Then
            Dim f As New Data.DataColumn(vHeader, GetType(System.String))
            dt.Columns.Add(f)
            f.AllowDBNull = True
        End If
    Loop
    cn.Close()

    '---> DATA ROWS FOR SCORES
    For Each row As DataRow In dt.Rows
        If Not dt.Columns.Contains("RANK") Then
            dt.Columns.Add("RANK").SetOrdinal(0)
        End If
        Dim v As Integer
        v = v + 1
        row(0) = v.ToString
        For col As Integer = 4 To dt.Columns.Count - 1
            '---> SQL COMMAND THAT GETS DATA (score) BASED ON THE 5 GENERATED COLUMNS ABOVE
            rs = cmd.ExecuteReader
            If rs.Read = True Then
                If Not String.IsNullOrEmpty(rs.Item("SCORE").ToString) Then
                    row(col) = rs.Item("SCORE").ToString
                Else
                    row(col) = rs.Item("REMTYPE").ToString
                End If
            End If
            cn.Close()
        Next
    Next

    '---> ADDITIONAL STATIC COLUMNS
    dt.Columns.Add("LE_SUM")
    dt.Columns.Add("LE_CNT")
    dt.Columns.Add("LE_AVE")
    dt.Columns.Add("UE_SUM")
    dt.Columns.Add("UE_CNT")
    dt.Columns.Add("UE_AVE")
    dt.Columns.Add("AVERAGE")
    dt.Columns.Add("CGRADE")
    dt.Columns.Add("+/-GPTS")
    dt.Columns.Add("CRANK")
    dt.Columns.Add("DEF")
    dt.Columns.Add("EXPTD")
    dt.Columns.Add("ABCNT")
    dt.Columns.Add("INC")

    Dim crpt As New ReportDocument()
    CrystalReportViewer1.DisplayGroupTree = False
    crpt.Load(Server.MapPath("~/CrystalReport.rpt"))
    crpt.SetDataSource(dt)
    CrystalReportViewer1.ReportSource = crpt
End Sub

如上所示,dtScores.xsd具有类似的数据列,用于生成水晶报告(是的,它正在工作)。但问题是前5列及其相应的数据。在Scores.xsd中,DataColumn5DataColumn9DataColumn24DataColumn28无法在Crystal Report中生成数据,因为在datatable dt中,没有相同的名称datacolumns。现在,我如何在Crystal Report中创建列,因为这些列正在根据Top 5进行更改。

0 个答案:

没有答案