Module VII
Module VII
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 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 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 Form's source code view and put the code on top
Imports CrystalDecisions.CrystalReports.Engine
NOTES:
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
Open Visual Studio .NET and select a new Visual Basic .NET
Project.
Select all table from the table list to right side list box, because
we are creating report from three tables ( OrderMaster,
OrderDetails, Product) .
The next step is to make relation between these selected tables.
Here we are connecting the related fields from each table. For
that we arrange the tables in visible area in the list (this is not
necessary ) and select the field we are going to make relation and
drag to the related field of the other table.
Then you can see Field Explorer in the Left hand side.
Fill the appropriate name for Name and Promting text fields
After creating the parameter field , we have to create the
selection formula for the Crystal Reports .
Then you can see the record Selection Formula Editor. This for
entering the selection formula. For that you have to select the
fields from above fields and make the formula .
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 .
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
crParameterDiscreteValue.Value = TextBox1.Text
crParameterFieldDefinitions = -
cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = _
crParameterFieldDefinitions.Item("Customername")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
End Sub
End Class
SITUATIONS :
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.
After you create the Crystal Reports you screen is look like the
following picture :
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
andCrystalReportViewer control to your form.
Imports CrystalDecisions.CrystalReports.Engine
In this tutorial we are taking the sum of field value of Total . This
is the continuation of the previous tutorial Crystal Report Formula
Field . So before we start this tutorial , take a look at the previous
tutorial Crystal Report Formula Field.
Here we are taking the grand total of the Total field . The Total
field is a Formula field is the result of qty X price .
Then you will get a screen , select the Total from the combo box
and Sum from next Combo Box , and summary location Grand
Total (Report Footer) . Click Ok button
Now you can see @Total is just below the Total field in the report
Footer.
Imports CrystalDecisions.CrystalReports.Engine
Next step is to select the fields from the tables . Here we are
selecting only Customername , orderdate from ordermastertable ,
Productname from product table and quantity from order details.
Click the Finish button because now we are not using other
functionalities of this wizard. After that you will get the Crystal
Reports designer window . You can arrange the fields in the
designer window according to your requirement to view the
report . For rearranging you can drag the field object in the
screen . For editing right click the field object and select Edit Text
Object. The following picture shows the sample of designer
window after rearrange the field.
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 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
CrystalReportViewer1.Refresh()
End Sub
End Class