Cast error when pass a parameter in localreport and reportviewer

hello friends,

i have a problem with my report when pass a pamameter in vb.net and VS 2005

The code is:

Dim
objParameter As ReportParameter

objParameter = New ReportParameter("Name", "test")

Me.ReportViewer1.LocalReport.SetParameters(objParameter)


the error is:

System.InvalidCastException was unhandled
  Message="Unable to cast object of type 'Microsoft.Reporting.WinForms.ReportParameter' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'."
  

Please help me

Rodrigo



Answer this question

Cast error when pass a parameter in localreport and reportviewer

  • Justdeserves

    I had that problem as well, if I don't supply a parameter, error will show.

    As the default report is useless, what I did is to set the reportview's visible=false.

    After a parameter is set, I set the visible=true.

    It's kind of silly, but it works.

    Good Luck,

    Long


  • juliam

    Does calling the .Refresh method programmatically cause it to show correctly

  • Nile

    ReportParameter moduleParameter = new ReportParameter("Module", 1234);
    ReportParameter moduleDescriptionParameter = new ReportParameter("ModuleDescription", "Test Module");
    ReportParameter statusParameter = new ReportParameter("BugStatus", "Open");
    this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { moduleParameter, moduleDescriptionParameter, statusParameter });



  • SoccerSarah

    Your post has been very helpful, thanks.

    I run into a problem though when the default value of the report parameter is not a constant such as a date.

    In the rdlc, the report parameter default can not be a field, i.e. only lets me hard code it. So the first time the report is run, the title of the report will say 1/1/2006 and the data is from 4/30/2006. After button_click refresh, the title updates.

    Any ideas


  • Mahmood Salamah

    I have tried: ReportViewer1.LocalReport.Refresh()

    in the page_load with no success.


  • dharmendra singh

    Hi Brian,

    I have the similar problem.

    Please,  you have one example of this.

    Thanks.

     

    Alex.

     



  • Sandeep Arora

    Can you please give me an working example in VB.net (Visual Studio 2005).

    My code is not working:

    Private Sub SetReportParameters()

    Dim p1 As New ReportParameter("name1", "test1")

    Dim p2 As New ReportParameter("name2", "test2")

    Dim param() As ReportParameter = {p1, p2}

    ReportViewer1.LocalReport.SetParameters(param)

    End Sub


  • Nicolas Frelat

    Brian thanks for you support.
  • Vijey Ashok

    Rod -

    Would you be so kind as to post a quick example of how you accomplished this using vb.net

    Thanks

    Mitch



  • ananda vardhana

    Hi,

    We are facing the same problem in passing parameters through VB.NET

    If anyone has the code snippet , can you please put it across here .

    Thanks and Regards,

    Soni


  • HerrLinder

    SetParameters takes an array of ReportParameter objects, not a single object.  You will need to create an array of one element and set that element to your instance of ReportParameter.
  • Desoohn

    Here's how I'm doing it.

    Dim RateId as integer = 5

    Dim params(0) As ReportParameter

    params(0) = New ReportParameter("RateId", RateId, False)

    Me.ReportViewer1.ServerReport.SetParameters(params)

    Me.ReportViewer1.ServerReport.Refresh()



  • Kent_8848

    Thanks for your response.

    The first time the report loads, the title shows the rdlc default value, which doesn't match the data default value.

    For example, "Income Statement as of " & parameters!portfoliodate.Value

    In the dataset the portfoliodate is the last date with data while in the rdlc fields are not allowed.

    Please let me know if I am missing something.

    Thanks.


  • George Clingerman

    To be clear, are you using ServerReport or a LocalReport

    Mitch



  • Cast error when pass a parameter in localreport and reportviewer