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

Pass parameter to sql where clause

3 Answers 872 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 16 Mar 2012, 03:59 PM

I have read through the documentation and to my understanding it is NOT possible to pass a parameter from an .aspx page directly to the SQL statement in the data table. I need to pull the data in its entirety and use parameters on the report to “filter” out what is not needed. Is this correct?

 

My issue is I need to pass a parameter to the WHERE clause of my SQL query to pull different users by a certain type. Unfortunately, because of the way our tables are setup I must programmatically switch between two separate queries or (data tables) depending on which user type is chosen. Also, pulling everything from our database and filtering at the report level has huge impacts on our report’s performance and I would like to stay away from that if possible.  

3 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 21 Mar 2012, 04:39 PM
Hi Tyler,

You can filter the sqlDataSource with parameters from the .aspx and you have plenty of options here. 
One way to do this is to create Report Parameters and assign them from the .aspx page. Then on Report_NeedDataSource you can access these parameters from the Processing.Report object and you can pass them to the SqlDataSource. 
Another way is to overload the default report constructor. Your constructor will take the parameters you need and call the default constructor first, then do the additional work on the SqlDataSource.
You can also access directly the SqlDataSource component of the report from the .aspx page and change its SelectCommand and parameters.

//if your data source is on your report you can access it like that:
var dataSource = myReport.DataSource as Telerik.Reporting.SqlDataSource;
 
//if you use Tables/Crosstabs/Lists then you can get their DataSources like this:
var table = myReport.Items.Find("tableName", true)[0] as Telerik.Reporting.Table;
var dataSource = table.DataSource as Telerik.Reporting.SqlDataSource;

All the best, Elian
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
0
Brian
Top achievements
Rank 1
answered on 23 Mar 2012, 10:24 PM
Elian,

I am in a similar situation, and I was wondering if you could provide a more complete example of assigning report parameters from an .aspx page.  We are passing a single parameter (an integer) as a post from one .aspx page to the page that hosts the report viewer.  We would like to use that parameter in our stored procedure for our report. 

Thanks,

Brian
0
Elian
Telerik team
answered on 28 Mar 2012, 03:53 PM
Hello Brian,

You can review the Using Parameters with SqlDataSource article. Also you can look into our demos, almost all of them use Report Parameters to filter the data from the database. As to the process of assigning the parameter values from the .aspx page, this article discusses the matter: Using Report Parameters Programmatically

Regards,
Elian
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
Tyler
Top achievements
Rank 1
Answers by
Elian
Telerik team
Brian
Top achievements
Rank 1
Share this question
or