f461fcd5 2f9a 4313 A938 Ed22ecb7a7e2Crystal Report BCS III
f461fcd5 2f9a 4313 A938 Ed22ecb7a7e2Crystal Report BCS III
f461fcd5 2f9a 4313 A938 Ed22ecb7a7e2Crystal Report BCS III
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
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 .
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 look 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
Crystal Reports Viewer control .
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
After you run the source code you will get the report like this.
Examining the Report Designer
Each report within your application is just like any other component that your application uses. It is
listed in the Solution Explorer window as a class in your project. When you double-click it, it opens the
report in design mode and you can make changes to it.
Each report starts with five sections: Report Header, Page Header, Detail, Page Footer, and ReportFooter.
These sections are described in Table 1-1.
To the left of the report layout is the Toolbox. When you have the report designer open, there are only a
few controls available in the Toolbox. They are the Text Object, Line Object, and Box Object. These are
the most basic of the controls available.
Formatting Objects
Formatting objects within your report can be done by using the Format Editor.
In order to open the Format Editor, you must right click on the object you wish to format and select,
depending on what type of object you have selected, Format Field, Format Text, or Format Object.
Whatever you have, the Format … option opens the Format Editor. The Format Editor dialog box presents
several different formatting options depending on the type of field you are attempting to format.
Adding Lines and Boxes to Your Report
Crystal allows you to precisely add a line or a box to your report. Add them by • Clicking the Insert Line
icon or the Insert Box icon on the Supplementary Toolbar.Note: Your mouse pointer changes to the shape
of a pencil. • Draw the line or box with the mouse pointer. Edit the line or box by right clicking on them
and choosing the Format Line or Format Box option from the menu.
Inserting Special Fields
Crystal Reports contains several special fields that are unrelated to fields within the
database.The special fields included are the following
First create a strongly typed datset and its Crystal Reports design . After create the dataset and Crystal
Reports design you should create a connection object and fetch the data from database.
Select the default form (Form1.vb) you created in VB.NET and drag one button and CrystalReportViewer
control to your form.
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If you have a Crystal Reports with Qty and Price , you need an additional field in your Crystal Reports for
the Total of QTY X PRICE . In this situation you have to use the Formula Field in Crystal Reports.
In this tutorial we are showing the all orders with qty and price and the total of each row , that means each
in each row we are showing the total of qty and price. Before starting this tutorial.
Create a new Crystal Reports with fields CustomerName , Order Date , Product Name and Product Price .
In that report selecting only four fields , here we need one more field Prodcut->Price .
After you create the Crystal Reports you screen is look like the following picture :
Next is to create the a Formula Field for showing the total of Qty and Price .
Right Click Formula Field in the Field Explorer and click New. Then you will get an Input Message Box ,
type Total in textbox and click Use Editor
Now you can see Formula Editor screen . Now you can enter which formula you want . Here we want the
result of Qty X Price . For that we select OrderDetails.Qty , the multiplication operator and Product.Price .
Double click each field for selection.
Now you can see Total Under the Formula Field . Drag the field in to the Crystal Reports where ever you
want .
Now the designing part is over . Select the default form (Form1.vb) you created in VB.NET and drag a
button and CrystalReportViewer control to your form.
When you run this program you will get the following screen.
Creating a Group or GroupName fields
Once you have determined that you would like to insert a group into your report, you must
either:
• Press the Insert Group icon located on the Supplementary toolbar or
• Choose the group command in the Insert menu.
The Insert Group dialog box appears. This box gives you the option to choose the field in
which you want to group as well as allowing you to define sorting and other options.
There are four choices used to determine the sort order of your group. They are:
1. In ascending order
2. In descending order
3. In original order
4. In specified order
In addition to the sort choices, there are two additional check boxes for the following
features:
Keep Group Together – Assures that page breaks will not separate groups. Use this option
ONLY if your groups are small. If you turn this feature on and you have a group that is
longer than one page, Crystal will move the entire group to the next page.
Repeat Group Header – If you have large groups, you may want the group header to appear
at the top of each new page to identify the group. This feature will do this automatically.
When a group is created Crystal adds two additional sections to the report.
1. A Group Header
2. A Group Footer
Once your group is created you can edit it by:
Right clicking on the gray area of the Group Header #1 section and
Choosing the Change Group option from the shortcut menu.
Right clicking groupname field under the Group name fields option in field explorer
Parameter fields
Parameters are used to take user inputs before the report is generated. User has to answer
the prompt before the report is generated and the report output depends on the response of
the user for the parameter value.
By using parameters with formulas and in the report, you can create a single report that
changes according to the requirement of different users.
Creating a Parameter Field
Enter the Prompting text, which is a text message that will indicate what you should
do or select (for example, "Enter the subheading for the report" or "Enter Start
Date").
Select the value type. The options are (examples of each type are shown in
parenthesis):
o Boolean (True or False)
o Currency ($534.12)
o Date (03/15/2002)
o DateTime (03/15/2002 2:49:09PM)
o Number (12345)
o String (text)
o Time (2:49:09PM)
In the Options frame, set the parameter to accept discrete values, range of values, or
both.
Click OK to return to the previous screen.
Click OK to save the parameter field.
Once you establish a parameter, you can use it in a formula, selection formula, or on
the report as a field.