Answered Difficulty setting ReportParameter

  • Monday, August 08, 2005 4:28 AM
     
     
    I am running into issues with setting the ReportParameter method. I am dynamcially setting an ObjectDataSource that is connected to a class object, and dynamically setting a ReportViewer Object. I am running into issues setting the parameters for the report dynamicallly. Here is my code:
    ------------------------------------------------------------------------

    public partial class ProductReport : System.Web.UI.Page

    {

    protected ReportViewer reportViewer = new ReportViewer();

    protected ObjectDataSource objDataSource = new ObjectDataSource();

    protected System.Web.UI.HtmlControls.HtmlTableCell tdRptViewer = new HtmlTableCell();

    protected void Page_Load(object sender, EventArgs e)

    {

    this.tdRptViewer.ID = "tdRptViewer";

    this.form1.Controls.Add(tdRptViewer);

    this.tdRptViewer.Focus();

    this.form1.Controls.Add(reportViewer);

    this.Form.Controls.Add(objDataSource);

    this.reportViewer.ProcessingMode = ProcessingMode.Local;

    this.reportViewer.LocalReport.DisplayName = "ShippedProduct.rdlc";

    this.reportViewer.LocalReport.ReportPath = "ShippedProduct.rdlc";

    //this.objDataSource = new ObjectDataSource("objDataSource", "GetProductShipped");

    this.objDataSource.ID = "objDataSource";

    this.objDataSource.SelectMethod = "GetProductShipped";

    this.objDataSource.TypeName = "Intel.JecortezSrv.DataLayer.ShippedProducts";

    this.objDataSource.SelectParameters.Add("spName", TypeCode.String, "ProductShipped");

    this.objDataSource.SelectParameters.Add("spParam", TypeCode.String, "@parameter1");

    this.objDataSource.SelectParameters.Add("spParamValues", TypeCode.String, "test");

    this.objDataSource.EnableViewState = true;

    this.objDataSource.Select();

    this.objDataSource.DataBind();

    this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("GetProductShipped", objDataSource.ID));

    this.reportViewer.LocalReport.SetParameters(new ReportParameter("spName", "ProductShipped", false));

    this.reportViewer.LocalReport.SetParameters(new ReportParameter("spParam", "@parameter1", false));

    this.reportViewer.LocalReport.SetParameters(new ReportParameter("spParamValues", "test", false));

    this.reportViewer.LocalReport.Refresh();

    }
    -------------------------------------------------------------------------

    The "this.reportViewer.LocalReport.SetParameters(new ReportParameter(parm, parm, parm))" lines are returning the following error:

    >>>Error 1 c:\Documents and Settings\jecortez.amr.000\My Documents\Visual Studio 2005\WebSites\SSRSWebConsole\ProductReport.aspx.cs(41): error CS1502: The best overloaded method match for 'Microsoft.Reporting.WebForms.Report.SetParameters(Microsoft.Reporting.WebForms.ReportParameter[])' has some invalid arguments<<<

    What is the issue here? Thanks

All Replies

  • Monday, August 08, 2005 4:44 AM
     
     Answered
    The method is expecting an array of parameters and you are giving it a single parameter. Try something like this instead:

    ReportParameter[] params = new ReportParameter[3];
    params[0] = new ReportParameter("spName", "ProductShipped", false);
    params[1] = new ReportParameter("spParam", "@parameter1", false);
    params[2] = new ReportParameter("spParamValues", "test", false);

    this.reportViewer.LocalReport.SetParameters(params);

  • Monday, August 08, 2005 3:11 PM
     
     

    Thanks. That worked nicely.

  • Monday, October 17, 2005 6:35 AM
     
     
    Hi,
      Could you please send the sample code.

    Regards,
    Baskar.D
  • Wednesday, November 30, 2005 9:46 PM
     
     
    Hello,
    I am having problems passing multivalue parameter to the report viewer through the .net layer.Please help
  • Friday, January 20, 2006 4:52 AM
     
     

    Which event do you put the code under to get the report filtered? I have it under ReportViewer1_Load, the following runs without error but I still get all values in the report.

    Dim params(0) As Microsoft.Reporting.WebForms.ReportParameter

    params(0) = New Microsoft.Reporting.WebForms.ReportParameter("ProductID", 47)

    ReportViewer1.LocalReport.SetParameters(params)

    ReportViewer1.LocalReport.Refresh()

  • Monday, March 27, 2006 8:30 PM
     
     

    Bravissimo, dopo 10 giorni di ricerche ho trovato la soluzione grazie a te.

    Thanks

    Giovanni

  • Tuesday, June 13, 2006 8:24 PM
     
     

    Referencing your code; why would I get a precompile error on the SetParameters (Params) statement and you don't?

    Me.ReportViewer2.ProcessingMode = ProcessingMode.Local

    Me.ReportViewer2.LocalReport.ReportPath = strReportPath

    ' Parameters

    Dim Params(3) As ReportParameter

    Params(0) = New ReportParameter("MainTitle", "New Main Title")

    Params(1) = New ReportParameter("X-Axis", "New X Axis")

    Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

    Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

    ' Precompile error for Params:   Value of type '1-dimensional array of Microsoft.Reporting.WinForms.ReportParameter' cannot be converted to 'String'.

    If I change it to  'Params.ToString'  the precompile swiggly line goes away but then I get an execution error:

    Unable to cast object of type 'Microsoft.Reporting.WinForms.ReportParameter' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'.

    Thanks,

    Bunk

  • Wednesday, June 14, 2006 8:01 PM
     
     
     

    Referencing your code; why would I get a precompile error on the SetParameters (Params) statement and you don't?

    Me.ReportViewer2.ProcessingMode = ProcessingMode.Local

    Me.ReportViewer2.LocalReport.ReportPath = strReportPath

    ' Parameters

    Dim Params(3) As ReportParameter

    Params(0) = New ReportParameter("MainTitle", "New Main Title")

    Params(1) = New ReportParameter("X-Axis", "New X Axis")

    Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

    Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

    ' Precompile error for Params:   Value of type '1-dimensional array of Microsoft.Reporting.WinForms.ReportParameter' cannot be converted to 'String'.

    If I change it to  'Params.ToString'  the precompile swiggly line goes away but then I get an execution error:

    Unable to cast object of type 'Microsoft.Reporting.WinForms.ReportParameter' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'.

    Thanks,

    Bunk

  • Thursday, June 28, 2007 11:20 PM
     
     

    I usually work in C#, but I think the change below should fix it:

     

    Dim Params(3) As ReportParameter

    Params(0) = New ReportParameter("MainTitle", "New Main Title")

    Params(1) = New ReportParameter("X-Axis", "New X Axis")

    Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

    'Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

    Me.ReportViewer2.LocalReport.SetParameters(Params)

     

    Hope that helps.

  • Monday, July 23, 2007 4:48 PM
     
     

    Hi Derek,

     

    I have exactly the same problem trying to set a parameter to a local report:

     

    Dim myReportParams(0) As ReportParameter

    myReportParams(0) = New ReportParameter("str_rpt_date", "2007/07/01")

    Me.ReportViewer1.LocalReport.SetParameters(myReportParams)

    Me.ReportViewer1.LocalReport.Refresh()

     

    Any ideas why the myReportParams(0) is not set the value? I can see that the NAME is set correctly thru the debugger though.

     

    Thanks,

    KC

  • Thursday, August 23, 2007 3:09 PM
     
     Proposed Answer

     

    Hi KC

    Try this it actually works..

     

            ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials
            ReportViewer1.ServerReport.ReportServerUrl = New Uri(strReportServer)
            ReportViewer1.ServerReport.ReportPath = strPATH

     

            Dim paramlist As New Generic.List(Of ReportParameter)

     

            paramlist.Add(New ReportParameter(strParmName1, strParmValue1, False))
            paramlist.Add(New ReportParameter(strParmName2, strParmValue2, False))

            ReportViewer1.ServerReport.SetParameters(paramlist)


            ReportViewer1.ServerReport.Refresh()

     

    Regards,

    David

  • Monday, August 27, 2007 4:03 AM
     
     

    I got an error  "Too many arguments to Public Sub New()" on

    Code Snippet
    ReportViewer1.ServerReport.SetParameters(New ReportParameter("intProjectID", 119))

     

     

    I also tried this and got error on multiple parameters starting the second parameter.  It works on single parameter.

    Code Snippet
    Dim param(2) As Microsoft.Reporting.WebForms.ReportParameter
    param(0) = New Microsoft.Reporting.WebForms.ReportParameter("ProjectID", Me.cboProject.SelectedValue)
    param(1) = New Microsoft.Reporting.WebForms.ReportParameter("RunBy", Session("strEmployeeName"))
    Me.ReportViewer1.ServerReport.SetParameters(param)

     

     

    What did I miss?  Thanks.

     

    DanYeung

  • Friday, October 19, 2007 8:55 PM
     
     

    Nice James Smile

     

    To the other vb.net guys - use it like so:

     

    Dim parms(0) As ReportParameter

    parms(0) = New ReportParameter("reportheader", "ProductShipped", False)

    MyReport.LocalReport.SetParameters(parms)

     

    Regards.

     Thomas Mathiesen

  • Thursday, November 08, 2007 10:46 PM
     
     

    Ok, so I have a local .rdlc report.  And a reportviewer.

    I've created the code:

     

    Dim Params(1) As ReportParameter

    Params(0) = New ReportParameter("ReportHeader","Bob",True)

    Me.ReportViewer1.LocalReport.SetParameters(Params)

    Me.ReportViewer1.LocalReport.Refresh()

     

    PLUS, I've got in the Report menu of the report itself, a parameter set in a dialogbox called ReportHeader that allows nulls and blanks and has no default value.

     

    I cannot seem to get the connection between the code above and the parameter in the dialog box.

     

    When I create a field on the report:

     

    Parameters!ReportHeader.Value  

     

    I get nothing.  Shouldn't I get Bob?

     

    How do I pass a value to this field?

     

  • Saturday, November 10, 2007 12:21 AM
     
     

    Did you assign the report path?

    Me.ReportViewer1.LocalReport.ReportPath = "/path/reportname"

     

    DanYeung

  • Monday, March 09, 2009 4:22 PM
     
     
     
    James Kovacs

    thanks a lot sir,
    it worked.
  • Friday, February 05, 2010 1:52 AM
     
     
    ****

     

    ReportParameter[] rp = new ReportParameter[1];

     

    rp[0] = new ReportParameter("WONumber",this.prmWO.Text.ToString(),false);

     

    this.reportViewer1.ServerReport.SetParameters(rp);

     

    this.reportViewer1.ServerReport.Refresh();
    ****

    When I try running this, the report doesn't open. It is just a blank report viewer. When I place a break on this and look for rp[0] in the Watch, I see the rp[0] name as "WONumber" but in the Values, I just see {System.Collections.Specialized.StringCollection}. The prmWO.text does show a value though.

    What am I missing here? Is the value even getting across?

  • Friday, February 26, 2010 5:02 PM
     
     
    Check your output window to see if it gives you any details.  I was trying to pass the parameters and had two problems.  The first one was that I didn't realize setparameters expects an array.  In my main report, I created a parameter named "applicationParameter".  In the output window it told me a parameter was being set that didn't exist.  I checked my code again, and I found I had typed "applicationParameters".  Once I changed it, then it worked. 

            Dim objP(0) As ReportParameter
            objP(0) = New ReportParameter("applicationParameter", "PARAMETER TEST")
            Me.ReportViewer1.LocalReport.SetParameters(objP)


  • Thursday, March 11, 2010 7:23 PM
     
     
    1. "WONumber" must be already defined as a parameter in the report
    2. Try this: add several values in 'Available values' section of 'Report Parameters' dialog screen
    3. Set a unique default value for this parameter on the same screen
    3. Try to pass one of these available values to the report (enter it in your prmWO.text textbox)

    Regards,
    M.R.
  • Thursday, September 22, 2011 6:51 AM
     
     
    I have faced a problem using the above method because the parameters are case sensitive(obviously my mistake), Double check all the names of the parameters and use them exactly within your code. 
    • Edited by Simon100100 Thursday, September 22, 2011 6:52 AM
    •