You are on page 1of 3

CC 103-COMPUTER PROGRAMMING 2

MODULE 9

VB.NET Crystal Report

Introduction

This module entitled VB.NET Crystal Report all about how to generate a reports using crystal report in VB.Net and steps
in how to create a crystal report base on the database with the table data.

I. Objectives

At the end of the end of this module,students should be able to:

1.Understand the concept of crystal report in VB.Net.

2. Can create a VB.Net application that can generate a printed report.

3.Describe how to use crystal report in a VB.Net program.

4. Explain how import the database table data in the crystal report.

5. Can configure the database connection and table data in a crystal report.

ll.Lecture

To create a sample Database and Tables and data for running Crystal Reports Tutorial.First,we have to

create a database. Give the database name as "crystaldb"

Create a DataBase "crystaldb"

In the crystaldb database,create three tables.

 OrderMaster
 OrderDetails
 Product

OrderMaster

 OrderMaster_id
 OrderMaster_date
 OrderMaster_customer
 OrderMaster_createduser

OrderDetails

 OrderDetails_id
 OrderDetails_masterid
 OrderDetails_productid
 OrderDetails_qty

Product

 Product_id
 Product_name
 Product_price

The following picture shows the relations of each table:


SQL command for creation tables are follows:

CREATE TABLE[dbo].[OrderMaster](

[OrderMaster_id] [int]NOT NULL,

[OrderMaster_date][datetime]NULL,

[OrderMaster_customername][varchar] (50),

[OrderMaster_createduser][varchar](50)

)ON[PRIMARY]

CREATE TABLE[dbo].[OrderDetails](

[OrderDetails_id][int]NOT NULL,

[OrderDetails_masterid][int]NULL,

[OrderDetails_productid][int] NULL,

[OrderDetails_qty][int]NULL

)ON[PRIMARY]

CREATE TABLE[dbo].[Product](

[Product_id][int]NOT NULL,

[Product_name][varchar](50),

[Product_price][numeric](18,0)NULL

)ON[PRIMARY]

Open Visual Studio.NET and select a new Visual Basic.NET Project.

Create a new Crystal Reports for Product table from the above database crystalDB. The Product Table has

three fields (Product_id,Product_name,Product_price)and we are showing the whole table data in the Crystal

Reports.

From main menu in Visual Studio select PROJECT-->Add New Item. Then Add New Item dialogue will

appear and select Crystal Reports from the dialogue box.

Select Report type from Crystal Reports gallery.

Next step is to select the appropriate connection to your database.Here we are going to select OLEDB

connection for SQL Server

Select OLE DB (ADO) from Create New Connection.

Select Microsoft OLE DB Provider for SQL Server.

Next screen is the SQL Server authentication screen. Select your SqliServer name, enter userid, password and select your
Database Name. Click next, Then the screen shows OLE DB Property values, leave it as it is, and click finish.

Then you will get your Server name under OLEDB Connection from there seleect database name (Crystaldb) and click the
tables, then you can see all your tables from your database9.

From the tables list select Product table to the right-side list.

Select all fields from Product table to the right-side list.

Click Finish Button. Then you can see the Crystal Reports designer window.can arrange the design

according your requirements.

Now the designing part is over and the next step is to call the created Crstal Reports in VB.NET

through Crystal Reports Viewer control.

Select the default form (Form 1.vb) you created in VB.NET and drag a buttod CrystalReportViewer control

to your form.

Select Form's source code view and put the code on top.
Imports CrystalDecisions.CrystalReports.Engine

Put the following source code in the button click event

Imports CrystalDecisions.CrystalReports.Engine

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles Button1.Click

Dim cryRpt As New ReportDocument

cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

CrystalReportViewer1.ReportSource = cryRpt

Crystal ReportViewer1.Refresh()

End Sub

End Class

NOTES:

cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

The Crystal Reports is in your project location, there you can see Crystal. So give the

full path name of report here.

Note: Attend the Google Meet for further explanation and example:S

You might also like