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

Passing a query parameter to a report

4 Answers 237 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
judo
Top achievements
Rank 1
judo asked on 16 Nov 2009, 01:27 AM
When I use the wizard to set up a report how can I pass a parameter to the report's query. I am simply looking to have a report embedded in a web page and the report will only show certain records (such as the last ten items purchased by the current user). This will require passing a parameter to the report each time it is generated.
I had a good dig through the docs but I cant see anything on this. Is there a good example of this (including creating the reports in a separate project and then using the reports in the web project and passing different parameters to the reports).

Thanks.

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 16 Nov 2009, 12:21 PM
Hello judo,

You cannot add parameters in the Sql query in the Report Wizard of Telerik Reporting. What you can do is enter the query without the param line and after it generates the typed dataset, you can open the dataset and edit the query directly through its designer (see screenshot).
You can also filter on database level directly like shown in the following video: Telerik Reporting - Design Time Support for Parameterized Queries.

Best wishes,
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.
0
judo
Top achievements
Rank 1
answered on 16 Nov 2009, 03:03 PM
I get it, thanks.

This seems like a lot of overhead, is using Reporting still a good solution under these circumstances? Just wondering if this is a typical situation where Reporting would be used....
0
Robert Schoenstein
Top achievements
Rank 1
answered on 16 Nov 2009, 03:55 PM
You can use LINQ to SQL in the 'NeedDataSource' event of the report:

        private void Report_NeedDataSource(object sender, EventArgs e) 
        { 
            Telerik.Reporting.Processing.Report report = (Telerik.Reporting.Processing.Report)sender; 
 
            try 
            { 
                report.DataSource = new Reporting_Rules().GetReportData(Convert.ToDateTime(report.Parameters["StartDate"]), 
                    Convert.ToDateTime(report.Parameters["EndDate"]), 
                    null
                    report.Parameters["ApplicationName"].ToString()); 
            } 
            catch (System.Exception ex) 
            { 
                System.Diagnostics.Debug.WriteLine(ex.Message); 
                throw ex; 
            } 
        }

Make sure you use 'ToList()' on your LINQ query.
0
maurizio brusini
Top achievements
Rank 1
answered on 02 Dec 2009, 11:00 AM
So you are saying that i cant build a query with WHERE CLAUSE ? or use the tecnique showed in the video.
You said we can edit the dataset and put the where clause...but after ? how can proceed for pass the value of parameter?
I'm studying in this days "Reporting" and i have a lot of confusion about  Report Parameter.
All my query are with where clause...so i shd write query without where clause and after create parameter..ok...but i stll have problems
how pass the value from the aspx page to reports.
Sorry for my bad english.

Maurizio
Tags
General Discussions
Asked by
judo
Top achievements
Rank 1
Answers by
Steve
Telerik team
judo
Top achievements
Rank 1
Robert Schoenstein
Top achievements
Rank 1
maurizio brusini
Top achievements
Rank 1
Share this question
or