VB.NET Crystal Reports Date parameter
All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure .
In this tutorial we are passing a date variable to Crystal Reports from VB.NET.
In the previous tutorials , we saw passing a string parameter to Crystal Reports , integer parameter to Crystal report from VB.NET and get the result. This tutorial is very similar to the above two tutorials , so please take look into the two tutorials before we start this one.
When we pass a Date parameter, we have to create a new date parameter in the Parameter Fields of Field Explorer. Then we will get the following screen and fill the fields like in the picture.
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 lists and make the formula .
Here we are making the formula like , select all records details from the tables whose order date is greater than the input date parameter. For doing this you have to select Ordermaster.orderdate , comparison operator and parameter date field from selection list of Formula Editor and make the formula.
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 Report 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 event
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 date , then you can see the report whose order date is greater than or equal to the entered date.
Here we got the result of orders whose date is greater than the entered date