locked
Passing parameters to RDLS reports RRS feed

  • Question

  • User-2020366656 posted

    Since I got very good feedbacks from you folks, I thought I would ask this to you about RDLCs.

    I'm trying to find a way to pass parameters to my report but I cant find the way. First, I generated a datatable programmatically but then I don't know how to pass it over to the report. Then I used the dataset build by the wizard in the Add Item functionnality but the query needs some parameters and again, don't know how to pass them.

     

    Thanks

    Friday, July 5, 2013 11:33 AM

All replies

  • User-183374066 posted

    Already resolved here http://forums.asp.net/t/1240076.aspx/1

    It asked and resolved many times on same forums

    See more links

    Regards

    Friday, July 5, 2013 12:13 PM
  • User-2020366656 posted

    Yes, but this post is for "Local reports". I'm not sure this is what I want. First I want the user to be able to print the RDLC report. Having it local disable this functionnality (I think).

     

    Second, I want to be able to pass the parameters on the server side code.

     

    thanks

    Friday, July 5, 2013 12:19 PM
  • User622904130 posted

    when i run ssrs reports locally, I feed it the dataset.  The dataset is where i feed the parameters.

    Using cmd As SqlCommand = ConnectionFactory.CreateCommand("your sql goes here")
    	Using cmd.Connection
    	    DatabaseHelper.AddParameter(cmd, "Param1", Param1)
    	    DatabaseHelper.AddParameter(cmd, "Param2", Param2)
    
    	    cmd.CommandTimeout = 360
    
    	    Using da As SqlDataAdapter = New Data.SqlClient.SqlDataAdapter(cmd)
    		da.Fill(dtD)
    	    End Using
    	End Using
    End Using
    
    'Assign dataset to report datasource
    Dim datasource As ReportDataSource = New ReportDataSource("dsReportData", dtD)
    
    'Assign datasource to reportviewer control
    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.DataSources.Add(datasource)
    ReportViewer1.LocalReport.Refresh()
    ReportViewer1.DataBind()

    Friday, July 5, 2013 12:50 PM
  • User-2020366656 posted

    What do you mean by : "when i run ssrs reports locally"

    If the application runs a a web server, can I use your code???

    Friday, July 5, 2013 12:53 PM
  • User-2020366656 posted

    I wrote some C# code based on this article and I get a run-time error. Note that I copied the syntax from MSDN:http://msdn.microsoft.com/en-us/library/vstudio/ms252146(v=vs.100).aspx

     

    string lts = "635086379830368001";
    Microsoft.Reporting.WebForms.ReportParameter myparam = new Microsoft.Reporting.WebForms.ReportParameter("ts", lts); ;
    ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { myparam });
    Server Error in '/JVPay' Application.
    --------------------------------------------------------------------------------
    
    An attempt was made to set a report parameter 'ts' that is not defined in this report. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: Microsoft.ReportingServices.Diagnostics.Utilities.UnknownReportParameterException: An attempt was made to set a report parameter 'ts' that is not defined in this report.
    
    Source Error: 
    
    
    Line 14:         string lts = "635086379830368001";
    Line 15:         Microsoft.Reporting.WebForms.ReportParameter myparam = new Microsoft.Reporting.WebForms.ReportParameter("ts", lts); ;
    Line 16:         ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { myparam });
    Line 17:     }
    Line 18: 
     
    
    Source File: c:\Users\mathieu\Documents\Visual Studio 2010\WebSites\JVPay\Users\Report.aspx.cs    Line: 16 
    
    Stack Trace: 
    
    
    [UnknownReportParameterException: An attempt was made to set a report parameter 'ts' that is not defined in this report.]
       Microsoft.ReportingServices.ReportProcessing.ParameterInfoCollection.Combine(ParameterInfoCollection oldParameters, ParameterInfoCollection newParameters, Boolean checkReadOnly, Boolean ignoreNewQueryParams, Boolean isParameterDefinitionUpdate, CultureInfo culture) +1110
       Microsoft.Reporting.LocalService.GetReportParameters(CatalogItemContextBase reportContext, NameValueCollection userSpecifiedValues, ParameterInfoCollection baseLineParameters, DatasourceCredentialsCollection credentials, ReportRuntimeSetup reportRuntimeSetup, CreateAndRegisterStream createStreamCallback) +162
       Microsoft.Reporting.WebForms.LocalReport.InternalGetReportParameters(CatalogItemContextBase reportContext, NameValueCollection userSpecifiedValues, ParameterInfoCollection baseLineParameters, DatasourceCredentialsCollection credentials, ReportRuntimeSetup reportRuntimeSetup) +182
    
    [LocalProcessingException: An error occurred during local report processing.]
       Microsoft.Reporting.WebForms.LocalReport.InternalGetReportParameters(CatalogItemContextBase reportContext, NameValueCollection userSpecifiedValues, ParameterInfoCollection baseLineParameters, DatasourceCredentialsCollection credentials, ReportRuntimeSetup reportRuntimeSetup) +263
       Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable`1 parameters) +250
       Report.Page_Load(Object sender, EventArgs e) in c:\Users\mathieu\Documents\Visual Studio 2010\WebSites\JVPay\Users\Report.aspx.cs:16
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
    
     
    
    
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.2012 

    Friday, July 5, 2013 12:55 PM
  • User622904130 posted

    Sorry, I thought you said you were running them locally.  If not couldn't you just pass the parameters in the url and show a pop up or load iframe with report?

    string server = "http://yourSSRSServer.com/";
    string url = server + "ReportServer?/" + "YourReportFolder" + "/reportName&Param1=" + Param1 + "&Param2=" + Param2 + "&rc:parameters=false";


     

    Friday, July 5, 2013 2:18 PM
  • User-2020366656 posted

    what do you mean by locally?

    Friday, July 5, 2013 2:52 PM
  • User622904130 posted

    the rdlc resides on the web server and not on the reporting server. 

    Friday, July 5, 2013 3:16 PM