VB.NET Crystal Reports Integer parameter

Before proceeding with this tutorial, it is essential to be aware that all programming samples presented here are based on the underlying database known as "crystaldb." To familiarize yourself with the database structure, kindly refer to the following link: Database Structure .

In this tutorial, our focus shifts towards passing an Integer parameter to Crystal Reports from VB.NET. This introduces a new aspect in comparison to the previous tutorial, where we explored passing a string parameter to Crystal Reports. Therefore, it is highly recommended to review the complete section on passing a string parameter to Crystal Reports from VB.NET to gain a comprehensive understanding of the overall process.

When passing an Integer parameter, we must create a new Integer parameter within the Parameter Fields section of the Field Explorer. By doing so, we gain access to the following screen, where we can input the necessary information based on the provided picture. This step enables us to establish the required parameter configuration within Crystal Reports.


Once the parameter field has been created, the next step involves creating the selection formula for Crystal Reports. To accomplish this, right-click on the Crystal Reports designer window and navigate to REPORT -> SELECTION FORMULA -> RECORD.

Upon selecting these options, the Record Selection Formula Editor will appear, allowing you to input the desired selection formula. To construct the formula, you will need to select the relevant fields from the available lists and combine them appropriately.

In this tutorial, we will illustrate the creation of a selection formula that selects records from the Product table where the value is greater than the input value. To achieve this, begin by selecting the field "Product_price" from the Product table. Next, choose the appropriate comparison operator, and finally, select the parameter that was created earlier. By double-clicking each field, they will automatically be added to the formula.

By following these steps, you will successfully construct the selection formula that filters the records based on the specified condition. This allows you to retrieve and display only the relevant data in the Crystal Reports based on the parameter input.


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 :

  1. Imports CrystalDecisions.CrystalReports.Engine
  2. Imports CrystalDecisions.Shared

Put the following source code in the button click event

Full Source VB.NET
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared 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") Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim crParameterValues As New ParameterValues Dim crParameterDiscreteValue As New ParameterDiscreteValue crParameterDiscreteValue.Value = Convert.ToInt32(TextBox1.Text) crParameterFieldDefinitions = _ cryRpt.DataDefinition.ParameterFields crParameterFieldDefinition = _ crParameterFieldDefinitions.Item("Price") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterValues.Clear() crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

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 any price , then you can see the report of the Product list whose price is greater than or equal to the entered price.


Here we got the result of Product list whose price is grater than 50.