Cast error when pass a parameter in localreport and reportviewer

Answered Cast error when pass a parameter in localreport and reportviewer

  • Friday, December 09, 2005 11:05 PM
     
     

    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

All Replies

  • Saturday, December 10, 2005 8:41 AM
    Moderator
     
     Answered
    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.
  • Sunday, December 11, 2005 4:35 AM
     
     
    Brian thanks for you support.
  • Friday, January 06, 2006 11:32 PM
     
     

    Hi Brian,

    I have the similar problem.

    Please,  you have one example of this.

    Thanks.

     

    Alex.

     

  • Thursday, January 19, 2006 3:14 PM
     
     Answered
    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 });


  • Thursday, January 19, 2006 5:04 PM
     
     

    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

  • Thursday, February 16, 2006 3:05 PM
     
     

    Rod -

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

    Thanks

    Mitch

  • Monday, April 03, 2006 6:46 PM
     
     

    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

  • Monday, April 03, 2006 9:12 PM
     
     

    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()

  • Wednesday, April 26, 2006 4:01 PM
     
     

    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?

  • Wednesday, April 26, 2006 5:39 PM
     
     
    Does calling the .Refresh method programmatically cause it to show correctly?
  • Wednesday, April 26, 2006 6:38 PM
     
     

    I have tried: ReportViewer1.LocalReport.Refresh()

    in the page_load with no success.

  • Wednesday, April 26, 2006 8:18 PM
     
     

    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

  • Thursday, April 27, 2006 5:18 PM
     
     

    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.

     

  • Thursday, April 27, 2006 5:59 PM
     
     

    To be clear, are you using ServerReport or a LocalReport?

    Mitch

     

  • Thursday, April 27, 2006 6:50 PM
     
     

    Local.

    Dario

  • Friday, April 28, 2006 2:01 AM
     
     

    I wish I could help, but I don't think I can.  I only use server reports and I don't ever set default values to parameters.  When I call the .Refresh command, my reports pull fresh data and show parameters correctly.

    Mitch

  • Friday, April 28, 2006 1:40 PM
     
     

    Thank you anyway.

    When I refresh the page it also shows data and rdlc parameters correctly.  The problem is the first time it loads.  I have tried ReportViewer1.LocalReport.Refresh() at the page_load with no success.

    Dario

  • Friday, April 28, 2006 4:54 PM
     
     

    What happens if you call .Refresh right after you set your parameters (Instead of on page_load?)

    Mitch

  • Monday, June 05, 2006 12:28 PM
     
     

    Dim params(0) As ReportParameter

    params(0) = New ReportParameter()

    params(0).Name = "ParamName"

    params(0).Values.Add(ValueNameAsString)

    Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "ProjectName.LocalReportName.rdlc"

    Me.ReportViewer1.LocalReport.SetParameters(params)

    Me.ReportViewer1.RefreshReport()

  • Wednesday, June 07, 2006 7:51 PM
     
     

    Thanks for your reponse.

    The code you sent works fine for the second time and onwards that the page with the report loads. 

    The first time, the report will show correctly the filtered data but "parameter.value" will show the default defined on the rdlc report/report parameters??

     

     

  • Tuesday, August 29, 2006 11:04 AM
     
     
    This code works fine. Thanks, you save me days of work!!
  • Tuesday, June 19, 2007 10:37 AM
     
     

    hi  marc

    I am doing this in the web page(c#)  and  I am getting the following exception.

     

    Microsoft.Reporting.WebForms.LocalProcessingException was caught
      Message="An error occurred during local report processing."
      Source="Microsoft.ReportViewer.WebForms"
      StackTrace:
           at Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable`1 parameters)
           at TestDefault2.SetParameters() in c:\RND2005\Report_14June\TestDefault2.aspx.cs:line 23

    how to solve it