如何在单个Crystal Report中加载多个IEnumerable作为DataSource?

时间:2014-05-02 17:42:38

标签: .net vb.net crystal-reports datasource ienumerable

我有一个从DataSet创建的Crystal Report。我使用IEnumerable加载它的DataSource 我是这样做的,因为我已经有一个ComponentModel.BindingList(Of Customer)作为列表框的数据源,所以我可以避免双重访问数据库。
我使用以下代码加载报告:

LoadReport("crCustomers.rpt", lstCustomers.DataSource)

Private Sub LoadReport(ByVal ReportName As String, ByVal ReportData As IEnumerable)
    'Load desired report
    Dim report As New ReportDocument
    report.Load(ReportName)

    'Load the data into the report
    report.SetDataSource(ReportData)

    'Set the report into the viewer
    crvReportViewer.ReportSource = report
End Sub

所有单一数据源报告都很奇怪,但现在我必须面对一个显示订单数据的报告以及与FK订单(Id)-OrderDetails链接的所有OrderDetails(发票行)的OrderId)。

如何将两个IEnumerable加载为DataSource?

1 个答案:

答案 0 :(得分:0)

我使用SubReport解决了它并加载SubReport数据源 以下代码加载客户的数据和客户的电话号码:

LoadReport("crCustomer.rpt", lstCustomers.DataSource, dgvPhones.DataSource)

Private Sub LoadReport(ByVal ReportName As String, ByVal ReportData As IEnumerable, ByVal ReportData2 As IEnumerable)
    'Load desired report
    Dim report As New ReportDocument
    report.Load(ReportName)

    'Load the data into the report
    report.SetDataSource(ReportData)
    report.OpenSubreport("crPhones").SetDataSource(ReportData2)

    'Set the report into the viewer
    crvReportViewer.ReportSource = report
End Sub
相关问题