Click here to Skip to main content
Click here to Skip to main content

How to pass discrete parameters to Crystal Reports

, 10 Jan 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
This is a simple and small user control that will help programmers to pass discrete parameters to Crystal Reports without writing lengthy code.


This is a simple and small user control that will help programmers to pass discrete parameters to Crystal Reports without writing lengthy code.

In this control, we are having two properties and one method:

  • ReportFileName

    This is a String parameter. This is to specify the report filename.

  • ParameterFields

    This is a String array parameter. This is to specify the parameters.

  • CrySet

    This method/function which will pass the corresponding parameter values to the report.

The Code

Before discussing the technical stuff, first we will see the pre-requirements. We need to add the following .NET references:

  • Crystaldecisions.crystalreports.engine
  • Crystaldecisions.reportsource
  • Crystaldecisions.shared


Dim pFields As New ParameterFields()
Dim pField As New ParameterField()
Dim disVal As New ParameterDiscreteValue()
Dim rVal As New ParameterRangeValue()

Assigning the Parameter Name and its Values

' parameter filed, must match with parameter in the report
pField.ParameterFieldName = "MyName"

disVal.Value = "CodeProject"     'Set the discrete Value
pField.CurrentValues.Add(disVal) 'Pass it to the parameter

With the example below, we can pass the range value:

rVal.StartValue = 150
rVal.EndValue = 200

Set the parameter fields collection into the viewer control:

crystalReportViewer1.ParameterFieldInfo = pFields

crystalReportViewer1.ReportSource = "c:\codeproject\About.rpt"

How to use this control

Step #1

Re-build the control.

Step #2

  1. Open a new project, add a crystalreportviewer control and a Button.
  2. Add this control by going to the toolbox control. Select the ‘General’ Tab, then right click on the mouse, then you will find an option in the popup as ‘Customize toolbox’. This will bring a window. Then select the tab called ‘.NET framework components’. Using the Browse button, add the UserControl. Then it will show it on the toolbox.
  3. Then add the control in our current form.
  4. Then write the following code for the Button as follows:

    Note: If necessary, change the path of the report filename.

    CryRepControl1.ReportFileName = "d:\VB.Net\AnyTest\MyProfile.rpt"
    CryRepControl1.ParameterFields(0) = "MyName;" & "J. Franklin Kennedy"
    CryRepControl1.ParameterFields(1) = "MyAge;" & "31"
    CryRepControl1.ParameterFields(2) = "DOB;" & "09/01/1973"
    CryRepControl1.ParameterFields(3) = "Married;" & "True"
    RptViewer1.ParameterFieldInfo = CryRepControl1.ParamFields
    RptViewer1.ReportSource = CryRepControl1.CrySet()
  5. Run the project.

    Note: The report ‘MyProfile.rpt’ is also in the ZIP file.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Kuwait Kuwait
I am J. Franklin Kennedy, Working as a programmer in application software developement.

Comments and Discussions

GeneralDisable parameter prompting and passing boolean parameter to Crystal Report 9 in VB.Net 2008 Pinmembercrystal_john6-Jun-11 2:22 
GeneralMy vote of 5 Pinmemberinamgul26-Apr-11 21:56 
GeneralMy vote of 5 Pinmembersalmanansari15-Jan-11 0:31 
Questionhow to use PinmemberRabbiiit29-Sep-10 21:37 
Generalthank you Pinmembeross_au5-May-10 22:24 
GeneralDiscrette param question PinmemberRaul H Chico13-Jan-10 22:41 
General:) :-D thank you very much. Pinmemberkisukortechai19-Sep-09 10:23 
GeneralExample project in vb with your class. PinmemberFastBurst17-Aug-09 13:49 
QuestionCrystal Report Pinmemberarbind21037917-Oct-07 1:51 
AnswerRe: Crystal Report Pinmemberkisukortechai19-Sep-09 10:35 
AnswerRe: Crystal Report PinmemberSreyas M N23-Oct-09 0:02 
GeneralMultiple Parameter values for 1 parameter Pinmemberckwizard7730-Jul-07 2:46 
Questionhow can i do it in .NET? PinmemberThe Putxi Project26-Mar-07 23:11 
GeneralSubreport Parameter count Posing Problem PinmemberRashmiSaggi19-Mar-07 16:28 
Questionhelp me with this error "Buffer too small for string or missing null byte" PinmemberMember #36291424-Jan-07 5:50 
Generalthe control works in web crystal Pinmembervladimirbc16-Aug-06 16:22 
GeneralError while trying to add control to the form PinmemberHarSha9916-May-06 3:39 
GeneralAddind data to the report in a loop Pinmemberworm3018-Feb-06 20:41 
Generalcascading prompts parameter values from Pinmembersurruchie25-Jan-06 8:21 
GeneralRe: cascading prompts parameter values from PinmemberDan_Gearhead19-Jan-09 21:54 
QuestionAbout Crystal PinmemberMuhammad Waqas Butt23-Sep-05 5:22 
GeneralWB Crystal Report Problem~ PinmemberMuhammad Waqas Butt23-Sep-05 0:30 
Could you please tell me how i show report contents on the bases of any input. I mean i have two tables [Stduent Master and Student Detail] one table have a field Student ID which is primary key and has two more field [ Student Name, Student Class]. In table two i have three record and Student Id as well, Now i want to show those record from Student Detail which have Student ID same in Crystal Report Detail Section.

StudentMaster.Student_id = StudentDetail.Student_ID

//Report Format

//Report Page Section
Student ID //From Master Table
Student Name //From Master Table

//Report Detail Section
Student ID | Student Fee Month | Student Fee
1 | Jan | Rs 1,000
1 | Feb | Rs 1,000
1 | Mar | Rs 1,000
1 | Apr | Rs 1,000

May be you got my points.Sorry for the Englis.

|Muhamad Waqas Butt|
GeneralCrystal Report Problem PinmemberMuhammad Waqas Butt23-Sep-05 0:29 
Generaltechnical question PinmemberAmeen Abudbush28-May-05 21:14 
QuestionHow to convert RDC from crystal 8.x to 9.0 PinmemberBenj1018-Apr-05 16:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.1 | Last Updated 10 Jan 2005
Article Copyright 2005 by kennedy_franklin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid