Report parameter used for SQL query parameter?

3 posts, 0 answers
  1. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 22 Nov 2009 Link to this post

    Hi.  I see that there is not very straightforward support for using parameterized SQL queries in the DataSets created by the designer wizard.  I have watched the video 'Telerik Reporting - Design Time Support for Parameterized Queries' which shows how to use a sqldataadapter and send it the parameter value from a windows (or web) app.  But what about using the report parameter on the report as the SQL parameter?  What code do I need for this?  I would like to use such a report as a multiple instance subreport on a main report that I can set report parameters from the main -> sub.  Thanks for your help.
  2. T. Stanley
    T. Stanley avatar
    22 posts
    Member since:
    Sep 2007

    Posted 23 Nov 2009 Link to this post

    So I have partially solved my challenge of using a report parameter as a SQL query parameter.  The error in the code written by the wizard is the absence of a parameter argument in the DataTableAdapter.Fill() method.  As a test I used the Fill() method that is found in the report class initialization routine, adding the report parameter as the needed second argument:

            public MDDaily()  
            {  
                /// <summary> 
                /// Required for telerik Reporting designer support  
                /// </summary> 
                InitializeComponent();  
     
                //  
                // TODO: Add any constructor code after InitializeComponent call  
                //  
     
                // TODO: This line of code loads data into the 'mDDaily_DataSet.MDDaily_DataSetTable' table. You can move, or remove it, as needed.  
                try  
                {  
                    this.mdDaily_DataSetTableAdapter2.Fill(this.mDDaily_DataSet1.MDDaily_DataSetTable, DateTime.Parse(this.Report.ReportParameters[0].Value.ToString()));  
                }  
                catch (System.Exception ex)  
                {  
                    // An error has occurred while filling the data set. Please check the exception for more information.  
                    System.Diagnostics.Debug.WriteLine(ex.Message);  
                }  
     
            }  
     


    At this point, I just need advice on where to inject this parameter value so that it is used when the query is triggered when the report is used as a subreport .  Again, any advice would be most appreciated.

    Thank you!

     
  3. DevCraft banner
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 24 Nov 2009 Link to this post

    Hello T. Stanley,

    That would be the NeedDataSource event of either the subreport item (i.e. usually in main report) or the NeedDataSource event of the report used as subreport itself. You can see similar implementation in the following KB article:Using data source with parameters in Telerik Reporting

    Greetings,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top