Pass Parameters to Stored Procedure

2 posts, 0 answers
  1. Lukasz
    Lukasz avatar
    3 posts
    Member since:
    Sep 2013

    Posted 30 Mar Link to this post

    Hello 

    I am trying to follow article below:

    https://docs.telerik.com/reporting/designing-reports-parameters-programmatic-control

    I designed my report in Standalone Report Designer(Test.trdp), Data source is stored procedure taking one parameter(@pDest).

    Now, I am trying to display report in WPF ReportViewer, how shall I pass this parameter to ReportViewer ?

           <tr:ReportViewer Grid.Row="0" x:Name="ReportViewer1" HorizontalAlignment="Stretch" EnableAccessibility="False">
                    <tr:ReportViewer.ReportSource>
                        <telerikReporting:UriReportSource Uri="Reports/Test.trdp"/>
                    </tr:ReportViewer.ReportSource>
                </tr:ReportViewer>

    How do I assign NeedDataSource event handler? 

     

  2. Katia
    Admin
    Katia avatar
    693 posts

    Posted 04 Apr Link to this post

    Hello Lukasz,

    SqlDataSource component will create a data source parameter for stored procedure parameter. On step 4 of SqlDataSource wizard, you can set the value of each data source parameter. It is convenient to map the value of data source parameter to the value of report parameter. This way the value of data source parameter can be updated using ReportSource.Parameters that are mapped to Report.ReportParameters. Consider this example:
    public partial class Window3 : Window
        {
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
               var uriReportSource = new Telerik.Reporting.UriReportSource();
               uriReportSource.Uri = "SampleReport.trdp";
               // Adding the initial parameter values
               uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("OrderNumber", "SO43659"));
               this.reportViewer1.ReportSource = uriReportSource;
            }
        }

    It is recommended using SqlDataSource wizard instead of in NeedDataSource event of the report for setting the values of data source parameters. If design-time approach is not suitable in your scenario, assigning NeedDataSource event handler can be achieved as following:
    public partial class Report1 : Telerik.Reporting.Report
        {
            public Report1()
            {
                //
                // Required for telerik Reporting designer support
                //
                InitializeComponent();
     
                //
                // TODO: Add any constructor code after InitializeComponent call
                //
                this.NeedDataSource += Report1_NeedDataSource;
            }
     
            private void Report1_NeedDataSource(object sender, System.EventArgs e)
            {
                //Take the Telerik.Reporting.Processing.Report instance
                Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender;
     
                // Transfer the value of the processing instance of ReportParameter
                // to the parameter value of the sqlDataSource component
                this.sqlDataSource1.Parameters[0].Value = report.Parameters["ManagerID"].Value;
     
                // Set the SqlDataSource component as it's DataSource
                report.DataSource = this.sqlDataSource1;
            }
        }

    You can find more useful information in Using the NeedDataSource event to connect data help article. To check alternative approaches for binding report to data check out Binding a Data item to Data.

    I hope this information will help.


    Regards,
    Katia
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top