0% found this document useful (0 votes)
5 views12 pages

Week 7

This lab manual provides step-by-step instructions for integrating Microsoft RDLC Report Viewer in Visual Studio and creating a sample database with employee data. It includes detailed guidance on installing necessary components, configuring ODBC drivers, and setting up a Visual Studio project to generate reports from the database. Additionally, it outlines lab tasks for replacing dummy data with real data and creating various reports based on employee and sales information.

Uploaded by

subhan138malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Week 7

This lab manual provides step-by-step instructions for integrating Microsoft RDLC Report Viewer in Visual Studio and creating a sample database with employee data. It includes detailed guidance on installing necessary components, configuring ODBC drivers, and setting up a Visual Studio project to generate reports from the database. Additionally, it outlines lab tasks for replacing dummy data with real data and creating various reports based on employee and sales information.

Uploaded by

subhan138malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Database Systems

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);

Install Microsoft RDLC Report Designer 2022


1. Open the link:
https://marketplace.visualstudio.com/items?itemName=ProBITo
ols.MicrosoftRdlcReportDesignerforVisualStudio2022
2. Click on “Get Started”. This will start the downloading of the
extension.
3. Once downloaded, run the file. Then click on “Install”. This
will complete the installation on its own. After the installation
click on Close.
4. Repeat the Same above 3 steps but with the link:
https://marketplace.visualstudio.com/items?itemName=ProBITo
ols.MicrosoftReportProjectsforVisualStudio2022
Database Systems-Manual 7 Page | 1
Configuring MySQL ODBC Driver
1. Open the following link:
https://dev.mysql.com/downloads/connector/odbc/. And click
download for the Windows (x86, 64-bit), MSI Installer

Figure 1ODBC Driver Installation

2. Then on the new page that pops up click on “No Thanks, just
start my download”.

Figure 2Download Confirmation

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.

Database Systems-Manual 7 Page | 2


Figure 3ODBC Setup Type

4. In windows search bar type “ODBC Data Sources (64-Bit)” and


open the app.

Figure 4ODBC Data Source App

5. Click on “ADD”

Database Systems-Manual 7 Page | 3


Figure 5User Data Sources

6. From the options available select “MySQL ODBC 9.1 Unicode


Driver” and click on Finish

Figure 6MySQL data source

7. In the Configuration window type in the details like Server IP,


Port, User, Password and after these from the database
dropdown select company and then click on OK

Database Systems-Manual 7 Page | 4


Figure 7MySQL Data Source Configuration

Prepare Visual Studio Project for Report


1. Open Visual Studio and click “Create a new Project”.
2. On the search bar type: “Windows Forms App (.NET
Framework)”.

Figure 8Visual Studio Project Create

Database Systems-Manual 7 Page | 5


3. From the list select the one that has “C#”, “Windows”,
“Desktop”. And then click on Next. Complete next project setup
options like name, location, etc.
4. Once Completed, open the project. From the top bar select
Tools->NuGet Package Manager->Package Manager
Console.

Figure 9Package Manager Console

5. Type in the following command in the console and hit enter.


Install - Package
Microsoft.ReportingServices.ReportViewerControl.Winforms -Version
150.1652.0

6. Once Installed, on the solution explorer, right click on your


project and go to Add->new Item.

Database Systems-Manual 7 Page | 6


Figure 10Add Item To Project

7. Create a C# class named: “EmployeeData”. This class will be


the model for our database table we created earlier. The
structure of the class will be:
public class EmployeeData
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Department { get; set; }
public double Salary { get; set; }
}

8. From the top bar select Build->Rebuild Solution.


9. On the solution explorer, right click on your project and go to:
Add->New Item.
10. In the top right, type “Report” in search bar. Under all the
options available select “Report” and click on Add.
11. Double click on the newly added item from the solution explorer
and then do the following shortcut key: “CTRL + ALT + D” if
Report Data window already not present.

Database Systems-Manual 7 Page | 7


12. From the Report Data tab, Select “New->Dataset”.

Figure 11Add Dataset to Report

13. In the Data Source Configuration Wizard, select “Object” and


then Next. In the next window select your “EmployeeData”
class from the dropdown, and then click Finish and then OK.

Figure 12Data Class Selection

Database Systems-Manual 7 Page | 8


14. While staying in the Report1.rdlc hit the shortcut key:
“CTRL+ALT+X”, it will open the toolbox side bar. Then drag
a text box inside the white box area of the report
15. Double click the text box and type “Employee Data” in it.
16. Drag a table from the toolbox into the report and adjust its
height, width, and position in the report.
17. Right click the table and click on Insert Column, Make sure
your table has 5 columns (Based on 5 attributes of our Class) if
not Insert that many columns.
18. Under the header of every Cell there is a small icon which
appears when mouse is over it like in the image below.

Figure 13Report Structure

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

Database Systems-Manual 7 Page | 9


Figure 14Report Structure With Table Mapping

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”.

Database Systems-Manual 7 Page | 10


33. See the function Form1_load: before the line of RefreshReport()
you have to add your code to fetch data from the database, but
for now lets do it with dummy data
private void Form1_Load(object sender, EventArgs e)
{
// Add logic to fetch data from database

this.employeeDataBindingSource.DataSource = new
List<EmployeeData>()
{
new EmployeeData(){ EmployeeID = 1, FirstName = "John",
LastName="Doe", Department = "HR", Salary = 50000.00 },

new EmployeeData(){ EmployeeID = 2, FirstName = "Jane",


LastName="Smith", Department = "IT", Salary = 70000.00 },

new EmployeeData(){ EmployeeID = 3, FirstName = "Robert",


LastName="Brown", Department = "Finance", Salary = 60000.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.

Figure 15Report in App

35. Microsoft RDLC Report Viewer provides features like printing


the report or exporting in pdf, Viewing in the print layout style
Database Systems-Manual 7 Page | 11
staying in the app. You can also set the export option as pdf,
word, or excel.

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.

Database Systems-Manual 7 Page | 12

You might also like