vb.net 如何使用 ReportViewer 设计将两个数据表添加到 Tablix

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18787907/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:04:07  来源:igfitidea点击:

How to Add Two DataTables to a Tablix Using ReportViewer Design

vb.netdatatablereportviewer

提问by Alex

I am trying to add two DataTables to a Table (tablix) in my report using ReportViewer.

我正在尝试使用 ReportViewer 将两个数据表添加到我的报告中的表 (tablix)。

DataTables

数据表

  • dtPrograms (Name, Description)
  • dtImprovements (Improvement)
  • dtPrograms (名称,描述)
  • dtImprovements (改进)

I'll have a list of programs and a list of improvements for each program.

我将有一个程序列表和每个程序的改进列表。

Here's an example of what I'm looking for:

这是我正在寻找的示例:

ReportViewer goal: Programs with their improvements

ReportViewer 目标:具有改进功能的程序

I'm not sure how to design my ReportViewer. Is using a Table (tablix) a good method or are there easier methods of doing so? Perhaps using a Matrix? How would you go about designing a report that contains two DataTables?

我不确定如何设计我的 ReportViewer。使用表格(tablix)是一种好方法还是有更简单的方法?也许使用矩阵?您将如何设计包含两个数据表的报告?

回答by Alex

Detailed Solution

详细解决方案

I manually created a DataSet (ds), a DataTable (dtTest) and manually populated it with information. For example:

我手动创建了一个 DataSet ( ds)、一个 DataTable ( dtTest) 并用信息手动填充它。例如:

ds.dtTest.Rows.Add("Test1", "Description 1", "Improvement 1 for Test1")
ds.dtTest.Rows.Add("Test1", "Description 1", "Improvement 2 for Test1")
ds.dtTest.Rows.Add("Test1", "Description 1", "Improvement 3 for Test1")
ds.dtTest.Rows.Add("Test1", "Description 1", "Improvement 4 for Test1")
ds.dtTest.Rows.Add("Test2", "Description 2", "Improvement 1 for Test2")
ds.dtTest.Rows.Add("Test2", "Description 2", "Improvement 2 for Test2")
ds.dtTest.Rows.Add("Test3", "Description 3", "Improvement 1 for Test3")
ds.dtTest.Rows.Add("Test3", "Description 3", "Improvement 2 for Test3")
ds.dtTest.Rows.Add("Test3", "Description 3", "Improvement 3 for Test3")
ds.dtTest.Rows.Add("Test3", "Description 3", "Improvement 4 for Test3")
ds.dtTest.Rows.Add("Test4", "Description 4", "Improvement 1 for Test4")


1. Add the Tablix to the Report

1. 将 Tablix 添加到报表中

New Tablix

新 Tablix



2. Remove all but 1 column. Keep the column that will be repeated

2. 删除除 1 列之外的所有列。保留将重复的列

In my case, I add the Improvement column here

就我而言,我在此处添加了改进列

Add Improvement column

添加改进列



3. Add Parent Group to the Improvement Column

3.在改进栏中添加父组

I right click on the Improvement cell and Add Group > Parent Group (Under Row Groups)

我右键单击改进单元格并添加组 > 父组(在行组下)

Add Row Group

添加行组



4. Group By Name

4. 按名称分组

Group By Name

按名称分组



5. Add a child group to your name column

5. 在您的姓名栏中添加一个子组

This is where I add my description

这是我添加描述的地方

Add Child Group to Name Column

将子组添加到名称列



6. Add Description

6. 添加说明

Add Description

添加说明

7. Remove Headers

7. 删除标题

Remove headers

删除标题



Result

结果

Here is the design:

这是设计:

Design

设计

Here is the final result: Result

这是最终结果: 结果

回答by Shelby115

In the Report Designer, Reports Items may have one and only one DataSet connected to it. So say your Tablix named "Tablix1" may only have one DataSet connected to it. However, if you have data from 2 Database Tables that you want to have displayed in one tablix, say "Tablix1" all you have to do it create a DataSet(.xsd) file, In there create a TableAdapter and use a query to join the two desired tables you want into one DataSet Object, then give the Report Designer that DataSet and connect "Tablix1" to it. This will allow for you to have (essentially) 2 DataSets for 1 Table.

在报表设计器中,报表项可能只有一个连接到它的数据集。所以说你的名为“Tablix1”的 Tablix 可能只有一个数据集连接到它。但是,如果您希望在一个 tablix 中显示来自 2 个数据库表的数据,请说“Tablix1”,您只需创建一个 DataSet(.xsd) 文件,在其中创建一个 TableAdapter 并使用查询加入将您想要的两个所需表放入一个数据集对象中,然后为报表设计器提供数据集并将“Tablix1”连接到它。这将允许您(基本上)为 1 个表拥有 2 个数据集。

The difference between Matrices and Tables are minuscule. If I'm not mistaken, matrices are for the case where you want Column & Row Headers and Tables are for the general column headers only. However, Tables & Matrices are both a "Tablix" when it comes to .rdlc reports. So there's nothing majorly different between the two, one is just simply easier to do row headers on.

矩阵和表格之间的差异很小。如果我没记错的话,矩阵适用于您想要列和行标题的情况,而表格仅适用于一般列标题。但是,当涉及 .rdlc 报告时,表格和矩阵都是“Tablix”。所以两者之间没有什么大的不同,一个只是更容易做行标题。