Crystal Report .NET - Passing a Parameter at run-time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a simple Crystal Report developed within .NET. Currently, it displays
all fields from a view. Could someone please tell me how I could pass a
parameter to the report to only display the record(s) affected? i.e. only
display information where the VisitID = 1 (for example). I can set it up to
be hard-coded to be VisitID = 1, but need to be able to do this dynamically
at run-time from within my .NET application... I would appreciate any help!

Thanks,
-Valerie
 
Use the following vb code:

Imports:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Code:

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues()
Dim crParameterDiscreteValue As New ParameterDiscreteValue()

' 1st Parameter
crParameterDiscreteValue.Value = VisitID
crParameterFieldDefinitions =
crReportDocument.DataDefinition.ParameterFields
crParameterFieldDefinition =
crParameterFieldDefinitions.Item("prmVisitID")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

In your crystal report, create a param field called prmVisitID. Drag the
VisitID on the form and right-click, choose Select Expert and make it equal
to the prmVisitID.
 
Back
Top