This is a migrated thread and some comments may be shown as answers.

Report parameter used for SQL query parameter?

2 Answers 229 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
T. Stanley
Top achievements
Rank 1
T. Stanley asked on 23 Nov 2009, 03:37 AM
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 Answers, 1 is accepted

Sort by
0
T. Stanley
Top achievements
Rank 1
answered on 23 Nov 2009, 06:42 PM
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!

 
0
Steve
Telerik team
answered on 24 Nov 2009, 03:23 PM
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.
Tags
General Discussions
Asked by
T. Stanley
Top achievements
Rank 1
Answers by
T. Stanley
Top achievements
Rank 1
Steve
Telerik team
Share this question
or