Visual Studio 2010 Local SSRS Report (.rdlc) with Object Data Source
I've created more projects using ReportViewer 2005 and 2008 in local processing mode than I can count on my hands. All Visual Studio 2005 or 2008 ASP.NET web forms projects. I always used some flavor of Object data source for the reports.
Tonight, I attempted to add the same functionality to a Visual Studio 2010 MVC 2 project and am failing miserably. First, the Add New Item > Reporting > Report is now a 2008 RDLC and not a 2005 RDLC report. Secondly, when trying to add a DataSet, my usual method of create a data proxy class with static methods that return IEnumerables(Of Stuff)
will not show up as sources in the DataSources drop down
Thirdly, my only option is to add a Database connection. There is no "Object Data Source" to pick from:
I'm stumped. Like I kind of alluded to, I have no problems whatsoever actually rendering a report using the ReportViewer control. What I can't do is figure out how set up a Data Source in these new-fangled 2008 reports with Visual Studio 开发者_如何学JAVA2010 so that I can pump a list of domain objects into the ReportViewer and display the report.
UPDATE
With some more research, I've found that MVC projects do not allow object data sources to be used within them. One solution for my issue is to create a separate project in the solution -- a web application, a service, or even just a class library, to add the report to and design it accordingly.
I'm still looking for alternatives here.
Here are a couple solutions. Number two is much better as it doesn't require needlessly duplicating your assemblies.
Solution 1 (okay)
As added to the question itself and described in the post Visual Studio 2010 Report Viewer - Object Datasource, just create a separate library for the project and add the rdlc file there. This appears to be a bug with the MVC Web Application project type itself so any other project type (like a Class Library) should work. The data source configuration wizard should now look like this:
Solution 2 (better)
As figured out in Can't see or add Website Data Sources in RDLC report in ASP.NET MVC, you can just add an .aspx page anywhere to the MVC project in order to trick Visual Studio into pulling in the right design time libraries.
Just do the following:
- Close all windows
- Clean & Rebuild Solution
- Add WebForm1.aspx to the Project
Open up the RDLC file and choose a DataSource from the dropdown:
The short answer: Yes you can use object data sources in RDLC 2008 (it's just not intuitive). Here's how:
Open your RDLC page (in [Design] view). After a moment, the "Data" tab will appear at the top of Visual Studio. Select "Add New Data Source", choose "Object", and Next. From there, you will be able to see the list of objects you can bind to. Pick your DTO/Business Object/whatever from your project and hit Finish. In the Report Data sidebar tab on the left side of Visual Studio, you will see your object added. Copy the datasource name it generated (it'll be something like "MyProject_MyObject").
Now in your controller, you can pull an IEnumerable of that DTO/BusinessObject and pass it in as the data parameter and your datasource name like this (sorry, no VB syntax):
ReportDataSource reportDataSource =
new ReportDataSource("MyProject_MyObject", myIEnumerable);
I had the same problem, but then move the report and the entities classes to another project separate from the WebAplication, when I did that, the wizard show another options other than DataBase Connection, so I add an Object DataSource to the C# Library. Then I use this post to retrieve the report definition and embedded to the .aspx, hope this help!!
I'm not sure if you're seeing what I'm seeing, but it looks to me that classes with private constructors (even with public static methods which return lists of the same class), don't show up in the list.
Criteria for object datasources to display in Visual Studio Report New DataSet?
will not show up as sources in the DataSources drop down
I had the same problem some days ago. I solved it by installing SP1 for VS10. http://www.microsoft.com/download/en/details.aspx?id=23691
I had the same problem and followed this instructions (Zilong Lu answer), Once I had the Handler for my report and the option for global datasource didn't show up, just the connection wizard. I did a right click on my project and clicked on build. After this I tried to add the global datasource again and the connection wizard didn't show up, but the global datasource option did.
精彩评论