質問

I have a Crystal Report created from a DataSet. I load its DataSource using an IEnumerable.
I do it this way because I already have a ComponentModel.BindingList(Of Customer) as datasource of a listbox and so I can avoid to double access to the database.
I load the report with the following code:

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

It works wonder with all single-DataSource reports, but now I have to face a report that shows data of an Order and also all OrderDetails(rows of the invoice) that are linked with a FK Order(Id)-OrderDetails(OrderId).

How can I load two IEnumerable as DataSource?

役に立ちましたか?

解決

I solved it using a SubReport and loading the SubReport datasource.
The following code loads customer's data and customer's phone numbers:

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top