Week 7
Week 7
Lab Manual 7
Learning Objectives
Integrate Microsoft RDLC Report Viewer in Visual Studio.
LO1: Integrate Microsoft RDLC Report Viewer in Visual
Studio.
Creating a Sample database and table
1. Execute the following MySQL script in MySQL Workbench
CREATE DATABASE company;
USE company;
CREATE TABLE EmployeeData (
EmployeeID INT AUTO_INCREMENT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10,2)
);
INSERT INTO EmployeeData (FirstName, LastName, Department,
Salary) VALUES
('John', 'Doe', 'HR', 50000),
('Jane', 'Smith', 'IT', 70000),
('Robert', 'Brown', 'Finance', 60000);
2. Then on the new page that pops up click on “No Thanks, just
start my download”.
3. After downloading run the installed file. Make sure you have
“Complete” checked on the setup type window then click on
Next and then Install.
5. Click on “ADD”
19. Click on each icon and map the column you want to display
inside it
20. When every column is mapped your report will look like the
image below
21. Save the report (You can build and design your complete report
as you want).
22. Open the Form1.cs
23. In the tool box scroll down till “General” Section. Right click on
general and select “Choose Items”.
24. Once the window is loaded, click on browse.
25. From the dialog box open your project’s folder and go to
(Your Project Path)->Packages-
>Microsoft.ReportingServices.ReportViewerControl.Winforms.
150.1652.0->lib->net40
26. From the folder select the file named:
“Microsoft.ReportViewer.WinForms.dll” and then click Open
and then OK.
27. Now in general section you will see “ReportViewer”.
28. Drag and drop that report inside your form window and click
“Dock in Parent Container”.
29. From Choose Report dropdown select your report you just
created.
30. Click on Choose Data Source
31. Under the dropdown of Data Source Instance select: “Other
data sources->project Data Sources->EmployeeData” and
then click OK.
32. In your form window right click and select “View Code”.
this.employeeDataBindingSource.DataSource = new
List<EmployeeData>()
{
new EmployeeData(){ EmployeeID = 1, FirstName = "John",
LastName="Doe", Department = "HR", Salary = 50000.00 },
this.reportViewer1.RefreshReport();
}
34. Save the File and then run the project. This will open the data
we just added in the load function.
Lab Tasks
Task 1: Replace Dummy Data with Database Data
1. Replace the dummy data in your Microsoft RDLC report with
real data fetched from the company database.
2. Use a Products table to display Product Name, Unit Price, and
Quantity Per Unit in the report.
3. Ensure you write the necessary SQL query in your C# code and
bind the resulting data to the report.
Task 2: Create a Report for Employees
1. Create a new RDLC report that lists the Employee Name, Title,
and Hire Date from the Employees table.
2. Include a filter option where users can view employees hired
after a specific date. Implement this filter in your C# code.
3. Add a professional-looking header with the title "Employee
Details Report."
Task 3: Create a Sales Report by Region
1. Create another RDLC report to display Region, Order ID, and
Order Date from the Orders table, grouped by region.
2. Add a summary at the end of the report to show the total number
of orders for each region.
3. Ensure proper formatting for dates and numeric values in the
report.