0
votes

I created a dataset which contains a table from my SQL Database named "BillHeaders"

Here's what my report viewer looks like, it will contain two reports. One that holds a job number and description, the other that holds a job number, description and contract number. Reportviewer

Here are my buttons that will execute either report

Two types of reports

Here are my reports in my "Reports" folder. Both constructed and ready to go. Reports folder

Unfortuantely when I use this code (respectively for each button):

Private Sub btnJobNoDesc_Click(sender As System.Object, e As System.EventArgs) Handles btnJobNoDesc.Click
    'Reset the viewer
    frmReportViewer.ReportViewer1.Reset()

    'Dim the required datasources. Need a seperate ReportDatasource for each table in the report
    Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource

    'Give datasource name and set the specific datatables
    ReportDataSource1.Name = "dsBillHeaders_BillHeaders"
    ReportDataSource1.Value = frmReportViewer.dsBillHeaders.BillHeaders

    'Clear the datasources in the report and add the new ones
    frmReportViewer.ReportViewer1.LocalReport.DataSources.Clear()
    frmReportViewer.ReportViewer1.LocalReport.DataSources.Add(ReportDataSource1)

    frmReportViewer.ReportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewer_Tutorial.rptJobNoDesc.rdlc"
    frmReportViewer.ReportViewer1.RefreshReport()

    frmReportViewer.Show()
End Sub

I get this result: Result

What am I doing wrong with my datasource?

2

2 Answers

2
votes

For one you are not setting the processing mode to local

Here is code that works, when I create the report I make sure to have the datasource name in the report correspond to the table name of my dataset, not sure if that is required but it keeps things simpler.

       _reportViewerNewContracts.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
        _reportViewerNewContracts.LocalReport.ReportPath = "Reports\NewContractsReport.rdlc"

        Dim reportDataSource1 As New Microsoft.Reporting.WinForms.ReportDataSource()
        reportDataSource1.Name = _contractDataset.NewContracts.TableName
        'Name of the report dataset in our .RDLC file
        reportDataSource1.Value = _contractDataset.NewContracts

        Me._reportViewerNewContracts.LocalReport.DataSources.Add(reportDataSource1)
        'fill data 
        _reportViewerNewContracts.RefreshReport()

(I have seen lots of sites that recommend the datasetname underscore tablename but that never worked for me)

1
votes

Here's what I figured out:

Private Sub btnJobNoDesc_Click(sender As System.Object, e As System.EventArgs) Handles btnJobNoDesc.Click
    'Reset the form
    Dim rv As New frmReportViewer

    'Reset the viewer
    rv.ReportViewer1.Reset()

    Dim ds As New dsBillHeaders
    Dim ta As New dsBillHeadersTableAdapters.BillHeadersTableAdapter
    ta.Fill(ds.BillHeaders)

    rv.ReportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewer_Tutorial.rptJobNoDesc.rdlc"
    rv.ReportViewer1.LocalReport.DataSources.Clear()
    Dim sReportDataSource As ReportDataSource
    sReportDataSource = New ReportDataSource()
    sReportDataSource.Name = "dsBillHeaders"
    sReportDataSource.Value = ds.BillHeaders
    rv.ReportViewer1.LocalReport.DataSources.Add(sReportDataSource)

    rv.ReportViewer1.RefreshReport()
    rv.Show()
End Sub

Using this code, I can generate multiple forms just by changing the name of the report on the ReportEmbeddedResource, sReportDataSource.Value and the dataset if necessary.