C# SSRS:具有两个数据源的主从报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/797601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSRS: Master-detail report with two datasources
提问by Svish
I have two local data sources that I can push into the report. Works no problem. But how do I set up the report? One data source contains a list of employees, and info about them. The other contains a bunch of working hours for each employee.
我有两个本地数据源可以推送到报告中。工作没问题。但是如何设置报告呢?一个数据源包含员工列表以及有关他们的信息。另一个包含每个员工的一堆工作时间。
I would like to use a table for the list of employees, and then have another table for the working hours beneath each employee (with their working hours).
我想使用一个表格来列出员工名单,然后在每个员工下方的工作时间(以及他们的工作时间)使用另一个表格。
Is this even possible? Do I have to use a Sub-Report? Would I have to merge them into one datasource? =/
这甚至可能吗?我必须使用子报告吗?我是否必须将它们合并到一个数据源中?=/
采纳答案by AaronSieb
As far as I can tell, it is impossible to nest one dataset inside of another one without using a subreport.
据我所知,如果不使用子报表,就不可能将一个数据集嵌套在另一个数据集中。
This means you need to do one of two things:
这意味着您需要做以下两件事之一:
Refactor your two datasources into a single datasource. For example, perform a join between the employees and the working hours for each employee. You can then use the grouping properties of the Table object to format the list the way you want it.
If joining the two data sources is not practical, you can use subreports to accomplish what you want. Create a subreport containing the working hours data source and give it a parameter for the current employee. Filter the working hours by this parameter.
In your parent report, you can place the subreport in the list, and pass the employee ID for the current row as a parameter.
Note that there are a few formatting quirks involved with using subreports. I've been able to work around them in most cases, but the preferred method would definitely be number one above.
将您的两个数据源重构为一个数据源。例如,在员工和每个员工的工作时间之间执行联接。然后,您可以使用 Table 对象的分组属性以您想要的方式格式化列表。
如果连接两个数据源不切实际,您可以使用子报表来完成您想要的。创建一个包含工作时间数据源的子报表,并为其提供当前员工的参数。通过该参数过滤工作时间。
在您的父报表中,您可以将子报表放在列表中,并将当前行的员工 ID 作为参数传递。
请注意,使用子报表有一些格式上的怪癖。在大多数情况下,我已经能够解决它们,但首选方法肯定是上面的第一。
回答by Pete H.
To set up multiple datasources...you need to place two separate list objects into the report. Go to the designer, and in the toolbox you can put a new "list" into it. Then, you can do another report. Link that second list to your secondary dataset, which you implement through the secondary datasource.
要设置多个数据源...您需要将两个单独的列表对象放入报表中。转到设计器,在工具箱中,您可以将新的“列表”放入其中。然后,您可以再做一次报告。将第二个列表链接到您通过辅助数据源实现的辅助数据集。
It's a little bit of a stretch, but the basic idea is that each list object in the report can only be linked to one datasource.
这有点牵强,但基本思想是报表中的每个列表对象只能链接到一个数据源。
回答by AaronSieb
Adding a new answer to make sure a notification is sent for it.
添加新答案以确保为其发送通知。
Using a subreport is the easiest method when it works. You can simply drag and drop a subreport onto a table cell, and it will fill that cell's content area. Right-clicking on the subreport will allow you to edit the parameters for the subreport. Like most values in SSRS, the parameters can be set to expressions which use the fields in the table.
使用子报表是最简单的方法。您可以简单地将子报表拖放到表格单元格上,它将填充该单元格的内容区域。右键单击子报表将允许您编辑子报表的参数。与 SSRS 中的大多数值一样,参数可以设置为使用表中字段的表达式。
Within the subreport, just filter your results to show only the records associated with the employee who was passed in as a parameter.
在子报表中,只需过滤您的结果以仅显示与作为参数传入的员工相关的记录。
The other route you can take is to merge your two datasources using a join. This will give you data something like this:
您可以采取的另一条路线是使用联接合并您的两个数据源。这将为您提供如下数据:
employee1 time1.1
employee1 time1.2
employee1 time1.3
employee1 time1.4
employee2 time2.1
employee2 time2.2
employee2 time2.3
You can then create a group on the repeated columns (employee in this example), and enable the HideDuplicates property on those columns. The result will look like this:
然后,您可以在重复列(本例中为员工)上创建一个组,并在这些列上启用 HideDuplicates 属性。结果将如下所示:
employee1 time1.1
time1.2
time1.3
time1.4
employee2 time2.1
time2.2
time2.3
回答by Augustin L. Manolache
In the report document class there is a property called "Database", which has a collection of tables. You can use "SetDataSource" on each one of those tables, in order to place the separate lists of objects into the report.
在报告文档类中有一个名为“数据库”的属性,它包含一组表。您可以在这些表中的每一个上使用“SetDataSource”,以便将单独的对象列表放入报告中。