VB.NET Crystal Reports String parameter
All programming samples featured in this tutorial are based on the underlying database named "crystaldb." Before diving into this tutorial, I encourage you to familiarize yourself with the structure of the database. To access the database structure, please click on the following link: Database Structure.
In this particular tutorial, we will focus on passing a string parameter from a VB.NET program to Crystal Reports. The objective is to retrieve and display all orders associated with a specific customer in the Crystal Reports.
Building upon the previous tutorial, which explained how to generate Crystal Reports from multiple tables, this tutorial introduces a slight variation. The key distinction lies in the inclusion of a string parameter representing the customer name. By providing the customer name as a parameter from the VB.NET program, Crystal Reports will fetch and present only the orders pertaining to that particular customer. To gain a better understanding of the overall process, I recommend reviewing the previous tutorial on generating Crystal Report from multiple tables.
In the previous section of this tutorial, we obtained a report that encompassed orders from all customers. However, in this particular scenario, we will narrow our focus to a single customer, allowing us to retrieve and display only the orders associated with that specific individual.
Hope you went through previous tutorial , if not click here ( Crystal Report from multiple tables ).
Next step is to create a string parameter in Crystal report.
Select the Field Explorer from CrystalReport Menu.
Then you can see Field Explorer in the Left hand side.
Select Parameter Field from Field Explorer and right Click.
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 .
For creating selection formula , Right click on Crystal Reports designer window , select REPORT -> SELECTION FORMULA -> RECORD .
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 .
First you have to select OrderMaster.OrderMaster_customername from Report Field and select the comparison operator and select the parameter field. Double click each field then it will be selected.
Form the following picture you can understand the selection fields.
After the creation of selection formula close that screen .
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 Textbox , button and CrystalReportViewer control to your form.
Select Form's source code view and import the following :
- Imports CrystalDecisions.CrystalReports.Engine
- Imports CrystalDecisions.Shared
Put the following source code in the button click eventFull Source VB.NET
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.
Now you can run the program . Enter a Customer Name(enter any existing customer from Ordermaster table) and click the button , then your report is look like the following picture.
Here we get the result of the Customer4's order details.