I have created a ClassLibrary called Reporting. I have placed all of my reports in this ClassLibrary, and now I would like to display these reports with some data.
I have read about the ReportDataSourceProvider, but I find it very hard to understand without a complete example on how to set the DataSource of a specific report. I would especially like to know if this is possible across two assemblies?
Does such an example exist?
Hi Christian,
You don't necessarily need to create a DataSourceProvider for that. If those reports are bound to a SQL DataSource, they should work as 'as is', unless for some reason you need to change the SQL sentece or the connection string dynamically.
In the samples distributed with Reporting there is an "OrdersReportEntityFrameworkDataSourceProvider" class that has an example of it. You basically need to implement IReportDataSourceProvider and return an IEnumerable with the data you want to display, and set the ReportDataSourceExport attribute in the class with a ReportSearchPattern="nameofyourreport.igr".
Hope that helps
Andres
Hello
I don't find the sample very helpful, so I will try to explain my situation a little better.
I have an assembly (lets call it MainApp)
This assembly contains the application that needs to show the reports using a XamReportViewer.
I also have an assembly called MainApp.Reporting. This assembly contains the reports (.igr-files).
MainApp.Reporting doesn't have any connection to my database. This is all handled by MainApp.
I would therefor think that I need to create an object in MainApp containing a collection af objects, and link this object to the report/XamReportViewer.
Am I completely wrong here?
I used an Object Data Source with an ObservableCollection containing the items I want to display.
The MainApp and MainApp.Reporting assemblies both have access to the same class used in the ObservableCollection
OK, so if I'm following you correctly everything is on Silverlight or WPF, both the Report and the Data.
You can bind the report directly to the data in the Report Viewer, with something like:
<ig:XamReportViewer Name="xamReportViewer1" VerticalAlignment="Top"> <ig:XamReportViewer.RenderSettings> <ig:ClientRenderSettings DefinitionUri="ReportLibrary.MyReport.igr, ReportLibrary" > <ig:ClientRenderSettings.DataSources> <ig:DataSource TargetDataSource="Orders" ItemsSource="{Binding TheOrdersCollection}" /> </ig:ClientRenderSettings.DataSources> </ig:ClientRenderSettings> </ig:XamReportViewer.RenderSettings></ig:XamReportViewer>
In this case, I'm assuming the XAML control DataContext is set to an instance of a class that has the a 'TheOrdersCollection' property with the report data.
Thanks. I will try that.
Just a couple of questions.
What is the TargetDataSource used for?
How should I define the DataSource in the report? Let's say I want to print out a table of orders. Which properties should I specify in the report/table in order to make it work with your example above?
By the way. I'm using WPF for my application
The ObjectDataSource you've created in the report has a name, which is displayed in the Report Data Explorer. That's the name you need to put in the TargetDataSource. Basically, you are telling the report viewer to bind the report data source with that name to the collection.
I'm not sure if that also answers the second question, but if you already have the report created, just using the above should work.
Regards,
Ok
So on runtime I can sort of "overwrite" the DataSource-reference created in the designer?
Yes.
For client-side rendering which is what you are doing, you can do that both by binding the DataSource to the report viewer or using a IReportDataSourceProvider. For server-side rendering, you can only do it with IReportDataSourceProvider.