如何在一个Crystal Report中添加两个数据表?

时间:2019-04-30 19:18:10

标签: vb.net crystal-reports

我正在尝试向Crystal Report添加两个数据表, 我在Crystal报表中插入了两个子报表,并添加了1个数据集,其中包含两个数据表,但是如何通过代码将两个数据表传递给子报表。

请注意::2个数据表是由查询而不是数据库中的表生成的。

        Dim Stmt1 As String = "select C_Code,C_name,Units from Courses where St_year like 'First' and C_Department like '%" & Label16.Text & "%' "
        Dim adp1 As New OleDbDataAdapter(Stmt1, con)
        Dim ds1 As New DataSet
        adp1.Fill(ds1)
        Dim dt1 = ds1.Tables(0)

        Dim Stmt2 As String = "select C_Code,C_name,Units from Courses where St_year like 'Second' and C_Department like '%" & Label16.Text & "%' "
        Dim adp2 As New OleDbDataAdapter(Stmt2, con)
        Dim ds2 As New DataSet
        adp2.Fill(ds2)
        Dim dt2 = ds2.Tables(0)

        Dim reportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
        reportDocument = New RptResultsCR

        reportDocument.Subreports("Subreport1").SetDataSource(dt1)
        reportDocument.Subreports("Subreport2").SetDataSource(dt2)

        RptCourse.CrystalReportViewer1.ReportSource = reportDocument

        RptCourse.ShowDialog()

enter image description here

1 个答案:

答案 0 :(得分:0)

使用以下行

RptDocument.Subreports(0).SetDataSource(ds1.Tables(0))