Your first VB.NET Crystal Reports - A step by step guide
By: Issac in VB.net Tutorials on 2009-02-21
Crystal Report is an application which can generate various reports from different data sources, we can create reports, print and preview those report using it, It is compatible with almost a developing platforms and databases, In this article you can find useful resources for generating reports from VB.NET with Crystal Report.
We can now see how to create a sample Database and Tables and data. First we have to create a database. Give the database name as "crystaldb"
Create a DataBase "crystaldb"
In the crystaldb database, let us create three tables OrderMaster, OrderDetails, Product.
OrderMaster
1. OrderMaster_id
2. OrderMaster_date
3. OrderMaster_customer
4. OrderMaster_createduser
OrderDetails
1. OrderDetails_id
2. OrderDetails_masterid
3. OrderDetails_productid
4. OrderDetails_qty
Product
1. Product_id
2. Product_name
3. Product_price
Now that you have a database you can start your first VB.NET Crystal Reports.
All Crystal Reports programming samples in these tutorials are based
upon the following database (crystaldb, the one we created through the previous
article).
Open Visual Studio .NET and select a new Visual
Basic .NET Project.
Create a new Crystal Report for Product table from
the above database crystalDB. The Product Table has three fields (Product_id,
Product_name, and Product_price).
From the 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.
Accept the default settings and click OK.
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 (
Select Microsoft OLE DB Provider for SQL
Server.
Next screen is the SQL Server authentication screen. Select your Sql Server
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
select database name (Crystaldb) and click the tables , then you can see all
your tables from your database.
From the tables list select Product table to the right side list.
Click Next Button
Select all fields from Product table to the right
side list.
Click Finish Button. Then you can see the Crystal
Reports designer window. You can arrange the design according your requirements.
Your screen looks like the following picture.
Now the designing part is over and the next step
is to call the created Crystal Reports in VB.NET through
Select the default form (Form1.vb) you created in VB.NET and drag a button
and 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
NOTES:
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
CrystalReportViewer1.Refresh()
End Sub
End Class
cryRpt.Load ("PUT
The Crystal Reports is in your project location, there you can see CrystalReport1.rpt.
So give the full path name of report here.
After you run the source code you will get the report like this.
Hope this article helps you to create your first Crystal Reports.
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net
Structured Exception Handling in VB.net
Creating Sub Procedures in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Specifying Optional Arguments with default values in Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
Throwing an Exception in VB.net
Comments