• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3953
  • Last Modified:

changing MS ReportViewer's datasource and report source at runtime in Visual Studio 2008

I'm needing to change a ReportViewer's datasource and the report that goes along with it at runtime - a user clicks a button for the report they want and it will be loaded into the report viewer.
The attached code, however, only works the first time,  if another button is clicked to load another report (with it's corresponding dataset), an error is displayed.
"A data source instance has not been supplied for the data source ...."
Only the first report clicked loads.

Any way to do this?
Private Sub btnOAReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOAReport.Click
        EnableOAReport()
    End Sub
    Private Sub EnableOAReport()
        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsOAReport_OrderProcHeaders", Me.DsOAReportBindingSource))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOA.rdlc"
        Me.ReportViewer1.RefreshReport()
    End Sub
 
    Private Sub btnOCReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOCReport.Click
        EnableOCReport()
    End Sub
    Private Sub EnableOCReport()
        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsOCReport_OrderProcHeaders", Me.DsOCReportBindingSource))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOC.rdlc"
        Me.ReportViewer1.RefreshReport()
    End Sub
 
    Private Sub btnORReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnORReport.Click
        EnableORReport()
    End Sub
    Private Sub EnableORReport()
        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsORReport_OrderProcHeaders", Me.DsORReportBindingSource))
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOR.rdlc"
        Me.ReportViewer1.RefreshReport()
    End Sub

Open in new window

0
bd9000
Asked:
bd9000
1 Solution
 
bd9000Author Commented:
Found the answer after trying every method for the ReportViewer instance.
ReportViewer1.Reset  did the trick.

I guess that makes me the resident EE ReportViewer expert now :)

    Private Sub btnOAReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOAReport.Click
        EnableOAReport()
    End Sub
    Private Sub EnableOAReport()
        Me.OrderProcHeadersTableAdapter1.Fill(Me.DsOAReport.OrderProcHeaders, StrToInt(OrderProc_idxTextBox.Text.Trim))
        Me.DsOAReportBindingSource.DataSource = Me.DsOAReport
        Me.ReportViewer1.Reset()
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOA.rdlc"
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsOAReport_OrderProcHeaders", Me.DsOAReportBindingSource))
        Me.ReportViewer1.RefreshReport()
    End Sub
 
    Private Sub btnOCReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOCReport.Click
        EnableOCReport()
    End Sub
    Private Sub EnableOCReport()
        Me.OrderProcHeadersTableAdapter2.Fill(Me.dsOCReport.OrderProcHeaders, StrToInt(OrderProc_idxTextBox.Text.Trim))
        Me.DsOCReportBindingSource.DataSource = Me.dsOCReport
        Me.ReportViewer1.Reset()
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOC.rdlc"
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsOCReport_OrderProcHeaders", Me.DsOCReportBindingSource))
        Me.ReportViewer1.RefreshReport()
    End Sub
 
    Private Sub btnORReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnORReport.Click
        EnableORReport()
    End Sub
    Private Sub EnableORReport()
        Me.OrderProcHeadersTableAdapter3.Fill(Me.dsORReport.OrderProcHeaders, StrToInt(OrderProc_idxTextBox.Text.Trim))
        Me.DsORReportBindingSource.DataSource = Me.dsORReport
        Me.ReportViewer1.Reset()
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "OrderProc.ReportOR.rdlc"
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dsORReport_OrderProcHeaders", Me.DsORReportBindingSource))
        Me.ReportViewer1.RefreshReport()
    End Sub

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now