Results 1 to 6 of 6

Thread: [RESOLVED] Cannot pass parameters to report

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    120

    Resolved [RESOLVED] Cannot pass parameters to report

    I have used this method many times with success, but all of a sudden its not working.

    I have a report with two parameters.

    I am trying to pass these two with the following code :

    Code:
    Me.PenalisasieTableAdapter.Fill(Me.LutzvilleDataSet.penalisasie)
    
            Dim param1 As New ReportParameter("ReportParameterALIASNAAM", KiesVorm.CmbAliasnaam4.SelectedItem.ToString())
    
            Dim param2 As New ReportParameter("ReportParameterPENALISASIE", KiesVorm.GepenaliseerComboBox.SelectedItem.ToString())
    
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param1, param2})
    
            Me.ReportViewer1.Show()
            Me.ReportViewer1.RefreshReport()
    I get the following error : : 'Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter[]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'.'

    I have searched in vain to get a solution. Please can someone help me, before I go mad.

    Regards

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    120

    Re: Cannot pass parameters to report

    Does anyone know if it it possible to filter a report's dataset with SQL rather than using the parameters in the report?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,870

    Re: Cannot pass parameters to report

    I don't know about that, but I have spotted an issue in the error message that is easy to overlook:

    Microsoft.Reporting.WebForms.ReportParameter
    Microsoft.Reporting.WinForms.ReportParameter


    It seems that somehow different assumptions are being made about whether you want the WebForms or WinForms variant... so specifying should solve it, eg:
    Code:
            Dim param1 As New Microsoft.Reporting.WinForms.ReportParameter("ReportParameterALIASNAAM", KiesVorm.CmbAliasnaam4.SelectedItem.ToString())
    
            Dim param2 As New Microsoft.Reporting.WinForms.ReportParameter("ReportParameterPENALISASIE", KiesVorm.GepenaliseerComboBox.SelectedItem.ToString())
    
            Me.ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WinForms.ReportParameter() {param1, param2})
    (I've assumed WinForms, so change that to WebForms if apt)

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,991

    Re: Cannot pass parameters to report

    Good catch there... I'd be more inclined to believe the wrong namespace was imported... changing that might also fix the problem.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    120

    Re: Cannot pass parameters to report

    Thank you for spotting that Si.
    It is as techgnome below suggested - I've imported the wrong namespace.

    Regards

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    120

    Re: Cannot pass parameters to report

    Thank you techgnome

    I have indeed imported the wrong namespace:

    Code:
    ''Imports Microsoft.Reporting.WebForms
    Imports Microsoft.Reporting.WinForms
    Regards

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width