简体   繁体   English

带有对象数据源的Visual Studio 2010本地SSRS报告(.rdlc)

[英]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. 我在本地处理模式下使用ReportViewer 2005和2008创建了更多项目,而不是我可以依赖的项目。 All Visual Studio 2005 or 2008 ASP.NET web forms projects. 所有Visual Studio 2005或2008 ASP.NET Web表单项目。 I always used some flavor of Object data source for the reports. 我总是使用一些Object数据源来报告。

Tonight, I attempted to add the same functionality to a Visual Studio 2010 MVC 2 project and am failing miserably. 今晚,我试图将相同的功能添加到Visual Studio 2010 MVC 2项目中,并且失败了。 First, the Add New Item > Reporting > Report is now a 2008 RDLC and not a 2005 RDLC report. 首先,添加新项目>报告>报告现在是2008 RDLC而不是2005 RDLC报告。 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 其次,在尝试添加DataSet时,我通常使用返回IEnumerables(Of Stuff)静态方法创建数据代理类的方法将不会显示为DataSources下拉列表中的源

空数据源

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. 就像我提到的那样,使用ReportViewer控件实际呈现报表时,我没有任何问题。 What I can't do is figure out how set up a Data Source in these new-fangled 2008 reports with Visual Studio 2010 so that I can pump a list of domain objects into the ReportViewer and display the report. 我不能做的是弄清楚如何使用Visual Studio 2010在这些新的2008年报告中设置数据源,以便我可以将一个域对象列表泵入ReportViewer并显示报告。

UPDATE UPDATE

With some more research, I've found that MVC projects do not allow object data sources to be used within them. 通过更多的研究,我发现MVC项目不允许在其中使用对象数据源。 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. 我的问题的一个解决方案是在解决方案中创建一个单独的项目 - 一个Web应用程序,一个服务,甚至只是一个类库,以便相应地添加报告并进行设计。

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) 解决方案1 (好的)

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. 添加到问题本身并在Visual Studio 2010报表查看器 - 对象数据源中添加后 ,只需为项目创建一个单独的库并在其中添加rdlc文件。 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. 这似乎是MVC Web应用程序项目类型本身的错误,因此任何其他项目类型(如类库)都应该起作用。 The data source configuration wizard should now look like this: 数据源配置向导现在应如下所示:

数据源配置向导

Solution 2 (better) 解决方案2 (更好)

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. 在ASP.NET MVC中的RDLC报告中看不到或添加网站数据源 ,您可以在MVC项目的任何位置添加.aspx页面,以欺骗Visual Studio引入正确的设计时库。

Just do the following: 只需执行以下操作:

  • Close all windows 关闭所有窗户
  • Clean & Rebuild Solution 清洁和重建解决方案
  • Add WebForm1.aspx to the Project 将WebForm1.aspx添加到项目中
  • Open up the RDLC file and choose a DataSource from the dropdown: 打开RDLC文件并从下拉列表中选择一个DataSource:

    DataSource下拉列表

The short answer: Yes you can use object data sources in RDLC 2008 (it's just not intuitive). 简短的回答:是的,你可以在RDLC 2008中使用对象数据源(它只是不直观)。 Here's how: 这是如何做:

Open your RDLC page (in [Design] view). 打开RDLC页面(在[Design]视图中)。 After a moment, the "Data" tab will appear at the top of Visual Studio. 片刻之后,“数据”选项卡将出现在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. 从项目中选择您的DTO /业务对象/任何内容,然后点击完成。 In the Report Data sidebar tab on the left side of Visual Studio, you will see your object added. 在Visual Studio左侧的“报表数据”侧栏选项卡中,您将看到添加了对象。 Copy the datasource name it generated (it'll be something like "MyProject_MyObject"). 复制它生成的数据源名称(它将类似于“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): 现在在你的控制器中,你可以拉出那个DTO / BusinessObject的IEnumerable并将其作为数据参数和你的数据源名称传递给它(抱歉,没有VB语法):

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. 我有同样的问题,但随后将报表和实体类移动到与WebAplication分开的另一个项目,当我这样做时,向导显示除DataBase Connection之外的其他选项,因此我将一个Object DataSource添加到C#Library。 Then I use this post to retrieve the report definition and embedded to the .aspx, hope this help!! 然后我用这篇文章检索报告定义并嵌入到.aspx中,希望对此有所帮助!!

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. 我遇到了同样的问题并遵循了这些说明(Zilong Lu回答),一旦我为报告提供了Handler并且没有显示全局数据源的选项,只需要连接向导。 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. 在此之后我尝试再次添加全局数据源并且连接向导没有显示,但是全局数据源选项确实如此。

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? 要在Visual Studio Report New DataSet中显示的对象数据源的标准?

will not show up as sources in the DataSources drop down 将不会显示为DataSources下拉列表中的源

I had the same problem some days ago. 几天前我遇到了同样的问题。 I solved it by installing SP1 for VS10. 我通过为VS10安装SP1解决了这个问题。 http://www.microsoft.com/download/en/details.aspx?id=23691 http://www.microsoft.com/download/en/details.aspx?id=23691

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM