【问题标题】:How to load multiple IEnumerable as DataSource in a single Crystal Report?如何在单个 Crystal Report 中加载多个 IEnumerable 作为 DataSource?
【发布时间】:2014-06-19 11:33:29
【问题描述】:

我有一个从数据集创建的 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 Order(Id)-OrderDetails(订单号)。

如何加载两个 IEnumerable 作为数据源?

【问题讨论】:

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


    【解决方案1】:

    我使用 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
    

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 2015-09-23
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      相关资源
      最近更新 更多