How to Add Two DataTables to a Tablix Using Report

2019-04-11 18:09发布

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

DataTables

  • dtPrograms (Name, Description)
  • dtImprovements (Improvement)

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

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?

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-11 18:20

Detailed Solution

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

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

New Tablix


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

In my case, I add the Improvement column here

Add Improvement column


3. Add Parent Group to the Improvement Column

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

Add Row Group


4. Group By Name

Group By Name


5. Add a child group to your name column

This is where I add my description

Add Child Group to Name Column


6. Add Description

Add Description

7. Remove Headers

Remove headers


Result

Here is the design:

Design

Here is the final result: Result

查看更多
【Aperson】
3楼-- · 2019-04-11 18:36

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.

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.

查看更多
登录 后发表回答