3 Replies - 264 Views - Last Post: 02 January 2018 - 12:44 AM Rate Topic: -----

#1 dhaggy1980   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 21-May 12

Need help switching reports when there are parameters involved.

Posted 27 December 2017 - 06:22 PM

Hi guy's I have a issue that i don't understand. I have a report viewer to display info from a sql database. I have a combobox to switch local reports. I used this website to understand how to switch reports. How to Switch Reports in a ReportViewer
Everything works as planned on that part. Now, I have made a report that has parameters in it. I get an error of
An error occurred during local report processing.
and the Title is
LocalProssessingException was unhandled
If I leave the report switcher intact. However, if I comment out the report switcher and add the report with my parameters to the report viewer itself it works and no error. I don't understand why this is happening.

Here is my code
Imports Microsoft.Reporting.WinForms
Public Class Form3

    Private Sub Form3_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Form1.Show()
    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Me.FullTableAdapter.FillByCurrent(Me._MARXMAN_PC_SQLEXPRESSDataSet.Full)
        rptViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)

        Me.rptViewer.RefreshReport()
        cboReportMenu.Items.Add("Current Residents")
        cboReportMenu.Items.Add("Single Person Report")
        cboReportMenu.SelectedIndex = 0
        Me.rptViewer.RefreshReport()
    End Sub

    Private Sub SwitchLocalReport(ByVal selectedreportname As String)

        Dim CurrentReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource()
       
        rptViewer.LocalReport.DataSources.Clear()

        Select Case selectedreportname
            Case "Current Residents"
                CurrentReportDataSource.Name = "CurrentDataSet"
                    CurrentReportDataSource.Value = Me.FullBindingSource
                    rptViewer.LocalReport.DataSources.Add(CurrentReportDataSource)
                    rptViewer.LocalReport.ReportEmbeddedResource = "Hand_Up_Tracking.Current.rdlc"


            Case "Single Person Report"
                CurrentReportDataSource.Name = "SingleDataSet"
                CurrentReportDataSource.Value = Me.FullBindingSource
                rptViewer.LocalReport.DataSources.Add(CurrentReportDataSource)
                rptViewer.LocalReport.ReportEmbeddedResource = "Hand_Up_Tracking.Single.rdlc"
               

            Case Else
                ' Error handling code here
        End Select

        rptViewer.RefreshReport()

    End Sub

    Private Sub cboReportMenu_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboReportMenu.SelectedIndexChanged
        SwitchLocalReport(cboReportMenu.SelectedItem.ToString)
    End Sub

   
     Private Sub btnSingle_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSingle.Click
        Dim Param As Microsoft.Reporting.WinForms.ReportParameter
        Dim ParamList As New List(Of Microsoft.Reporting.WinForms.ReportParameter)

        Param = New Microsoft.Reporting.WinForms.ReportParameter("ReportParameter1", txtID.Text)
        ParamList.Add(Param)

        Me.rptViewer.LocalReport.SetParameters(ParamList)
        rptViewer.RefreshReport()
    End Sub
End Class


I have tried moving the entire section from btnSingle to SwitchLocalReports. I've tried commenting certain sections out of SwitchLocalReports. I don't know I'm at a loss. Any help would be great.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help switching reports when there are parameters involved.

#2 andrewsw   User is offline

  • Bouncy!
  • member icon

Reputation: 6563
  • View blog
  • Posts: 26,615
  • Joined: 12-December 12

Re: Need help switching reports when there are parameters involved.

Posted 28 December 2017 - 12:11 AM

What seems most likely to me is that when you Clear the DataSources it will also discard the parameter list. In which case, the error probably occurs because of missing parameters.

So, when switching to the single report, reinstate the parameters before refreshing the report.
Was This Post Helpful? 0
  • +
  • -

#3 dhaggy1980   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 21-May 12

Re: Need help switching reports when there are parameters involved.

Posted 28 December 2017 - 07:25 AM

View Postandrewsw, on 28 December 2017 - 01:11 AM, said:

What seems most likely to me is that when you Clear the DataSources it will also discard the parameter list. In which case, the error probably occurs because of missing parameters.

So, when switching to the single report, reinstate the parameters before refreshing the report.

Thanks didn't think about that I'll try when I get home from work.
Was This Post Helpful? 0
  • +
  • -

#4 dhaggy1980   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 21-May 12

Re: Need help switching reports when there are parameters involved.

Posted 02 January 2018 - 12:44 AM

Thanks that worked!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1