SSRS:具有两个数据源的主从报告
我有两个本地数据源,可以将它们推送到报告中。 工作没问题。 但如何设置报告呢? 一个数据源包含员工列表及其相关信息。 另一个包含每个员工的大量工作时间。
我想使用一个表来存储员工列表,然后使用另一个表来存储每个员工下面的工作时间(以及他们的工作时间)。
这可能吗? 我必须使用子报告吗? 我是否必须将它们合并到一个数据源中? =/
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? =/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,如果不使用子报表,就不可能将一个数据集嵌套在另一个数据集内。
这意味着您需要执行以下两件事之一:
将两个数据源重构为单个数据源。 例如,在员工和每个员工的工作时间之间执行联接。 然后,您可以使用 Table 对象的分组属性按照您想要的方式设置列表格式。
如果连接两个数据源不切实际,您可以使用子报表来完成您想要的操作。 创建一个包含工作时间数据源的子报表,并为其指定当前员工的参数。 按此参数过滤工作时间。
在父报表中,您可以将子报表放入列表中,并将当前行的员工 ID 作为参数传递。
请注意,使用子报表会出现一些格式问题。 在大多数情况下我都能够解决这些问题,但首选方法肯定是上面的第一个方法。
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.
添加新答案以确保为其发送通知。
使用子报表是最简单的方法。 您只需将子报表拖放到表格单元格上,它将填充该单元格的内容区域。 右键单击子报表将允许您编辑子报表的参数。 与 SSRS 中的大多数值一样,可以将参数设置为使用表中字段的表达式。
在子报表中,只需过滤结果即可仅显示与作为参数传入的员工关联的记录。
您可以采取的另一种方法是使用联接合并两个数据源。 这将为您提供如下数据:
然后您可以在重复列(本例中为员工)上创建一个组,并在这些列上启用 HideDuplicates 属性。 结果将如下所示:
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.
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:
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:
要设置多个数据源...您需要将两个单独的列表对象放入报表中。 转到设计器,在工具箱中您可以将新的“列表”放入其中。 然后,您可以再做一份报告。 将第二个列表链接到您的辅助数据集,您可以通过辅助数据源实现该数据集。
这有点牵强,但基本思想是报表中的每个列表对象只能链接到一个数据源。
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.
在报表文档类中有一个名为“Database”的属性,其中包含表的集合。 您可以在每个表上使用“SetDataSource”,以便将单独的对象列表放入报表中。
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.