[OBSOLETE. Instead use the approach suggested in How to: Connect to a SQL Server Database Using Stored Procedure help article.]
I’ve blogged in the past about the many ways you can connect your reports to data. Because the developers who build Telerik’s Reporting Tool wanted to make it as flexible as possible, they designed it to have the ability to bind to any object that implements one of the four supported interfaces: IEnumerable, IListSource, ITypedList, and IDbDataAdapter. What does this mean for you? No matter where your data comes from – plain SQL queries, stored procedures, web services, etc – you can bind it to a Telerik report.
Okay, I realize that showing an example is much more effective than just talking about about how easy it is to bind data to your reports. So I’m going to walk you through connecting a report to the stored procedures in your database.
First, create a class library project in Visual Studio and add a Telerik Report item to your project. When you add this item, you’ll be greeted with the Telerik Report Wizard. Go ahead and cancel out of it as we’ll be designing our report manually this time.
When the new DataSet is generated, you’ll be greeted with a blank design surface. Drag a TableAdapter onto the design surface from your Visual Studio Toolbox. This will launch the TableAdapter Configuration Wizard. On the first page of the wizard, select the connection string you want to use to connect to the Northwind database. If one is not already set up and available in the drop down list, click New Connection… to create a new one.
To add two new report parameters to the report, go to your report properties in the Visual Studio Properties window and select the ellipses next to the Report Parameters property.
private void AnnualSalesReport_NeedDataSource(object sender, EventArgs e)
{
string category = (string)this.ReportParameters["Category"].Value;
string year = (string)this.ReportParameters["Year"].Value;
SalesTableAdapter adapter = new SalesTableAdapter();
SalesDataSet.SalesDataTable data = adapter.GetSalesByCategory(category, year);
((Telerik.Reporting.Processing.Report)sender).DataSource = data.AsDataView();
}
Now you can preview the results in the report designer by clicking on the Preview tab.
Conclusion
Binding to any data source is easy with Telerik Reporting if you remember one thing: the objects that are returned from your data source must match one of the supported interfaces.
If you’d like to see more examples of using stored procedures with Telerik reports, check out this Knowledge Base article on the topic.