Introduction

One of the most common types of reports is a master detail report. The following tutorial provides the most straightforward method for creating this type of a report in Visual Studio 2005. We will be using the Access NorthWind database as our data source. If you do not have the NorthWind database, you can download it here.

Click Next ("Save the connection string to the application configuration file").

Choose Views, then check the "Sales by Category" view. Note: When doing this for real, you will need to create a flat view in your data source that provides data with the top level information repeated on each line. This sample view has been created in this manner.

Click Finish. The NorthWindDataSet should now appear in your Data Sources window.

There are three main ways to create a hierarchical report using grouping. This example will use the "Master List Detail Table" method. The other two methods are "Master List Detail List" and "Single Table Master Detail". An alternate method to using groups is to use sub-reports.

3. Add the master list

Open your Toolbox.

In the Report Items section, drag a list onto your report. (This will be the master list.)

Open the Data Sources Window.

Drag the CategoryID and CategoryName fields into the list (Master section).

Right click the list, and select Properties.

Click "Edit Details Group".

In the "Group on" section, select the master record's ID field, CategoryID in this case.

Optional: In the document map label field, select the master record's description field, CategoryName in this case. This will provide a clickable tree in the report viewer to switch between master records.

Optional: Click page break at the end. This will put page breaks between each master record.

4. Add the detail table

Drag a table from the Report Items toolbox section into your master list.

Right-click the top left corner of the table, and select Properties.

Set the DataSet name to the NorthwindDataSet_Sales_by_Category table. Some clarification: the report designer refers to a result set as a "DataSet". This is not the same as a .NET Framework "DataSet". The report designer's "DataSet" more closely relates to a .NET DataTable.

Select the Groups tab.

Click Details Grouping... Note: In a single table master detail report, you would instead click "Add...".

Group on each detail column. In this case: ProductName and ProductSales.

Click OK.

Click OK.

Drop the ProductName field into the Detail (middle) row of the first column in the table.

Drop the ProductSales field into the Detail (middle) row of the second column in the table.

Optional: Resize the parent list textboxes, bold the table's column headers, and add another textbox label for the ID.

5. Create the report form

Open Form1 from Solution Explorer.

Drop a ReportViewer onto the form (from the data section of the Toolbox). A dialog should appear. If this dialog disappears, use the triangle button on the top right border of the ReportViewer to see it again.

Select the report from the Choose Report combo.

Click Dock in the parent container to fill it to the form. Note: This adds the DataSet, TableAdapter, data source, and adapter code to fill the adapter.

Run the project.

With optional formatting:

Advanced

1. Filter the results (WHERE clause)

Right-click the DataSet in Solution Explorer and select View Designer.

Right-click the TableAdapter section of the DataTable, and select Configure....

Modify the SQL statement to include the WHERE clause. For SQL Server, you would use a named parameter @CategoryId. OLEDB adapters require ? parameters.

Click Finish.

Add the appropriate controls for your form to provide the parameter value.

Move the code to fill the adapter, and refresh the report from the Form Load event to the event that will load the report. For example: "Go" button Click event.

Provide the required parameter in the adapter's Fill method.

Conclusion

Please comment on anything that needs further clarification, or with any questions on implementing this. Also, please provide suggestions before rating the article less than a 5.

Some of the bigger questions:1. What is the meaning of my life?To satisfy the purpose of your creator(s). (Meaning must derive from purpose. Those who create you, give you meaning.)

2. Who is my creator?Ultimately, God is your creator. God designed and created the universe and everything in it. You and others in your life can also be a part of your creation, overriding or furthering God's purpose.

3. What is God's purpose for me?To love and be loved by your creator and others and to enjoy the life you've been given.This can be distinguished two ways. a. Use your built in common sense (morality/feelings) b. Use the creator's handbook. Fortunately our creator did not abandon us. He is with us now and even lived and died as one of us. Check out his biography in "The Bible"

Note on free-will vs. predetermination:God exists outside the constraints of time. He exists at every point in time simultaneously and knew of your birth and every decision you will/have made. But this does not mean God predetermined any of it. Pre and post are time related concepts that do not apply to God. God always has been and always will be. He determines our universe to exist, gives it the parameters of natural law, and allows us to make our own way through it (free-will). Note that these are all present tense, it would be more appropriate to use past, present, and future tense combined. God's purpose is for us to love him and one another. But a prerequisite of love is the free-will to love. So even though God wants us to love him/others, he can not ensure it. He can, however, help us if we allow him to. A miracle is God modifying natural parameters in response to human will.