需要向 RDLC 添加额外的 DataTable
我需要将应用程序的主数据集中的第二个数据表添加到报告中,但运气不佳。
我们在 RDLC 文件中有几个简单的本地报告,每个报告都有一个基于应用程序数据库中的视图的 DataTable
。我需要改进其中一个报告以添加另一个表中的信息。这个另一个表是在我们在 .NET 2.0 WinForms 应用程序中用于报告的同一核心 DataSet
中定义的。由于这两个表位于同一个数据集中,我是否可以确保两个表都加载到数据集中,然后将报表指向数据集而不是数据表?还有别的事吗?
不用说,我已经玩了一段时间了,但没有取得任何进展。
TIA, 马特
I need to add a second DataTable from our app's main DataSet into a report, but not having much luck.
We have several simple local reports in RDLC files, each with a single DataTable
based on a view in our application DB. I need to improve one of the reports to add information from another table. This other table is defined in the same core DataSet
which we use for reports in our .NET 2.0 WinForms application. Since the two tables are in the same DataSet, can I just make sure that both tables are loaded into the DataSet and then point the report at the DataSet instead of the DataTable? Something else?
Needless to say, I've been playing around with this for a while and not getting anywhere.
TIA,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我成功了,现在回想起来,这非常简单。我只是不知道使用哪些菜单来让 VS 连接所有内容,以及按什么顺序执行它们。
查看表单的 Designer.cs 实际上是我所做的最有帮助的事情。我注意到 ReportViewer 有一个指向第一个表的默认 BindingSource。最初,我一直想为 BindingSource 提供一个 DataSet 而不是 DataTable,但后来我决定尝试制作第二个 BindingSource。
也许有更好的方法,但这基本上就是我最终所做的:
在设计器中使用 RDLC,单击“报告”菜单,然后单击“数据源”。
在设计器中使用 RDLC,
在“报告数据源”对话框中,从下拉列表中选择其他数据表,然后单击“添加到报告”。 (我还将新数据源重命名为附加数据表的名称;VS 基于完整命名空间创建了一些巨大的长名称。)确定关闭对话框。
在包含 ReportViewer 控件的表单设计器上,单击 ReportViewer 的智能标记(控件右上角的小箭头),然后选择“重新绑定数据源”。这使得第二个 BindingSource 出现在设计器表面的底部。
再次单击 ReportViewer 的智能标记,这次选择“选择数据源”以确认 ReportViewer 现在有两个数据源,每个数据源都绑定到表单上现在的
BindingSource
实例之一。修改了我的表单的 OnLoad 代码,以将行加载到第二个 DataTable 中。
修改
返回 RDLC 文件,添加一个新表并将详细单元格设置为第二个 DataTable 中的字段 - 它成功了!
希望有一天这能为其他人节省几个小时。
OK, I got this working and, in retrospect, it was pretty easy. I just didn't know which menus to use for getting VS to hook everything up, and which order to do them in.
Looking at the Designer.cs for my form was actually the most helpful thing I did. I noticed was that the ReportViewer has a default BindingSource pointed at the first table. Originally, I was hung up on trying to give the BindingSource a DataSet instead of a DataTable, but then I decided to try making a second BindingSource instead.
Maybe there's a better way, but here's basically what I ended up doing:
With the RDLC in the designer, clicked the Report menu then Data Sources.
On the Report Data Sources dialog, chose the additional DataTable from the drop-down and clicked Add to Report. (I also renamed the new data source to just be the name of the additional data table; VS had created some gigantic long name based on the full namesspace.) OK to close the dialog.
On the designer for the form that contains my ReportViewer control, clicked the ReportViewer's smart tag (the little arrow in the top right corner of the control) and then selected Rebind Data Sources. This made a second BindingSource appear at the bottom of the Designer surface.
Clicked the ReportViewer's smart tag again and this time chose "Choose Data Sources" to confirm that the ReportViewer now had two data sources, each bound to one of
BindingSource
instances now on the form.Revised the my form's OnLoad code to load rows into the second DataTable.
Went back to the RDLC file, added a new table and set the detail cells to fields in the second DataTable -- and it worked!
Hopefully this will save someone else a couple hours someday.
找到了在 Visual Studio 2010 中使用它的方法。
点击查看> ReportData,当看到报告数据时,单击“数据源”,然后单击“添加”。执行此操作的次数与所需数据集的数量相同。
现在,在报表查看器的智能标签中,单击选择数据源,这将显示每个数据集。要将数据集与绑定源关联,您必须单击“项目”,然后进一步单击直到获得适当的类,这将导致创建绑定源。
如果您有多个 tablix,并且当报表显示在报表查看器上时,您必须在同一报表中将绑定源与它们关联,则此解决方法非常有用
Figured out a way to use it in Visual Studio 2010.
Click on View > ReportData and when the report data is seen , click on Datasources and then click on add. DO this as many times as the number of datasets needed.
Now in the smart tags of the reportviewer, click on choose datasources, this will show each of the datasets. To associate the datasets with a binding source, you will have to click on Project and then further click till you get the appropriate class, this will cause the binding sources to be created.
This work around is very useful if you have multiple tablixes and you have to associate a binding source to them within the same report when the report is displayed on the report viewer