Setting Parameters in Crystal Reports .NET

I see this question quite often in the Crystal Reports forum at ASP.NET.  My advice is always to download the web samples at:

Visual Basic .NET Web Samples

C# .NET Web Sample Applications

Then, follow the Readme file to install the “Discrete Parameters” example.  This has been my guide, and it works great.

Additional help and tutorials are in the CR SDK:

Crystal Reports .NET SDK – Additional Conceptual Documentation and Tutorials

This file contains additional conceptual information and tutorials for using Crystal Reports in Visual Studio .NET (including a developer reference). This documentation applies to Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003. Sample applications built using these tutorials are available for download (

Crystal Reports .NET SDK – Sample Applications from Tutorials

This file contains C# and VB .NET Windows and web sample applications. These samples were built using the tutorials provided in the ‘Crystal Reports .NET SDK – Additional Documentation and Tutorials’ ( These sample applications applies to: Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003.  

A number of methods out there use the CrystalReportViewer control to set parameters.  That’s great unless you need to export your report to PDF (or XLS or RTF).  This is a code snippet I use, which sets parameter values directly on the Report Document object:

  rptCount = New ReportDocument

  ”Get the collection of parameters from the report
  crParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields
  ”Access the specified parameter from the collection
  crParameter1 = crParameterFieldDefinitions.Item(“Param1”)
  crParameter2 = crParameterFieldDefinitions.Item(“Param2″)

  ”Get the current values from the parameter field.  At this point
  ”there are zero values set.
  crParameter1Values = crParameter1.CurrentValues
  crParameter2Values = crParameter2.CurrentValues

  ”Set the current values for the parameter field
  crDiscrete1Value = New ParameterDiscreteValue
  crDiscrete1Value.Value = Request.Form(“param1value“)

  crDiscrete2Value = New ParameterDiscreteValue
  crDiscrete2Value.Value = Request.Form(“param2value“)

  ”Add the first current value for the parameter field

  ”All current parameter values must be applied for the parameter field.

Once you get used to working with parameters, you can “automagically” display them on your web pages.  This series of articles shows you how to get a list of parameters from your report file, and display them on your web form, where you can prompt for inputs:

Automagically displaying a Crystal Reports Parameters – Part I
Automagically displaying a Crystal Reports Parameters – Part II
Automagically displaying a Crystal Reports Parameters – Part III

If you’re new to Crystal Reports .NET, get this book:

Crystal Reports .NET Programming

It is both an introduction to Crystal Reports .NET, as well as a object model programming guide/reference.  Examples are in both VB.NET and C#.