Setting Parameters


Parameter fields work almost exactly the same as database credentials. Both viewers prompt for parameters if they are required by the report but not supplied by the developer. These parameter prompting screens are shown in Figures 29.8 and 29.9.

Figure 29.8. The Windows Forms Viewer prompting for parameter values.


Figure 29.9. The Web Forms Viewer prompting for parameter values.


Again, the parameter prompting screens are useful but sometimes don't fit the look and feel of the application or simply need to be suppressed entirely. Another common usage of customized parameter prompting screens is to have the parameter pick list's values come directly from the database so they are always up to date. To do this you would use the ReportDocument object to set the parameters before passing it to the viewer to display. This is done via the ReportDocument's SetParameterValue method. There are three versions of this method:

  • SetParameterValue(index As Integer, val As Object) is used to set a parameter value by index.

  • SetParameterValue(name As String, val As Object) is used to set a parameter value by name.

  • SetParameterValue(name As String, val As Object, subreport As String) is used to set a parameter for a subreport by parameter name and subreport name.

An example of this is

Dim Report As New ReportDocument() Report.Load("C:\Reports\Orders.rpt") Report.SetParameterValue("Geography", "North America") Report.SetParameterValue("Start Date", DateTime.Now) Viewer.ReportSource = Report


For parameters that accept multiple values, pass in an array of those values.




Crystal Reports XI(c) Official Guide
Crystal Reports XI Official Guide
ISBN: 0672329174
EAN: 2147483647
Year: N/A
Pages: 365

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net