1214110 - How to pass a Date/Time parameter to a report at runtime using VB .NET

SAP Knowledge Base Articles - public

1214110 - How to pass a Date/Time parameter to a report at runtime using VB .NET


A VB .NET application uses Crystal Reports for Visual Studio .NET as the reporting development tool.

How do you pass a date/time value to a date/time parameter contained in a main report (using the engine object model)?


To pass a date/time value to a date/time parameter, use the following steps:

1. Add a report to your project.

2. Add a date/time parameter to the report and name it "DateTimeParam".

3. Add the following lines of code to the top of the code page:

'Import the following namespaces
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

4. Add the following lines of code to a click event or form load event, etc.

'Setting date/time parameters at runtime
Dim crReport As New CrystalReport1()
'ParameterFieldDefinitions and ParameterFieldDefinition are from the
'CrystalDecisions.CrystalReports.Engine namespace
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
'ParameterValues and ParameterDiscreteValue are from the CrystalDecisions.Shared
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue()
'Set Date/Time discrete parameter value
crParameterDiscreteValue.Value = CDate("8/9/1969 12:01:00 AM")
'Access first parameter field definition
crParameterFieldDefinitions = crReport.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("DateTimeParam")
crParameterValues = crParameterFieldDefinition.CurrentValues
'Clear existing parameter values
'Add the parameter value
'Apply the current value to the parameter definition

5. Pass the report object to the Windows Form or Web Forms viewer and run the application.

Note: =====

For .NET sample applications, go to http://support.businessobjects.com/search. Using the pull down menus, select 'Crystal Reports' as the Product, and select '.NET' as the product version.



.NET DOTNET VB.NET VBDOTNET CD.CR.ENGINE PARAMETER DATETIME DATE-TIME Crystal Reports for Visual Studio Parameter Fields Date-Time , c2010251 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To


Crystal Reports 2008 V1 ; SAP Crystal Reports 10.0 ; SAP Crystal Reports XI ; SAP Crystal Reports XI R2