How to pass parameters to CrystalReportViewer and ReportDocument ...

zhaozj2021-02-16  53

First, CrystalReportViewer passes CrystalReportViewer.ParameterfieldInfo properties ...

1. CrystalReportViewer members public instance attribute ParameterfieldInfo inherits Parameterfields. Get or set the parameter field collection.

Second, ReportDocument passes the ReportDocument.DataDefinition.Parameterfields property ...

1. ReportDocument member public instance attribute DATADEFINITION DATADEFINITION. Get the DATADEFINITION object.

2, DATADEFINITION Members Public Example Attribute Parameterfields ParameterfieldDefinitions. Get the ParameterfieldDefinitions collection.

Third, the parameter field is customized as CrystalReportViewer

Reference: Setting Parameters | Binding Options for Windows Form View | Web Form Viewer Bindings

The user can be supported by the parameter in the Crystal report. This parameter has a variety of uses. For example, the parameters are based on the database field and allow the user to specify the value of the field to filter data in the report. Use the parameter field to apply the condition format to the report. Use the parameter field to define the sort order. The following example shows how to set the parameter field value through the code at runtime. This example explains how to set two different parameters: the first is a multi-value discrete parameter, the second is the area value parameter.

Modify the parameter field at runtime

[Visual Basic] 'The declaration passed the parameters to the variable required by the viewer control. Dim paramfields as new parameterfields () Dim paramfield as new parameterfield () DIM Discreteval as new parameterdiscretevalue () Dim Rangeval As new parameterRangeValue ()

'The first parameter is a discrete parameter having multiple values.

'Set the name of the parameter field, it must be "consistent with the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer Name"

'Set the first discrete value and pass it to this parameter discreteval.Value = "AIC Childrens" paramfield.currentValues.Add (Discreteval)

'Set the second discrete value and pass it to this parameter. The 'Discreteval variable is set to a new value, so that the previous settings will not be overwritten. Discreteval = new parameterdiscretevalue () discreteval.value = "aruba sport" paramfield.currentvalues.add (discreteval)

'Add this parameter to the parameter field collection. Paramfields.Add (paramfield)

'The second parameter is the zone value. The PARAMFIELD variable 'is set to a new value, so that the previous settings will not be overwritten. Paramfield = new parameterfield ()

'Set the name of the parameter field, it must be "consistent with the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer ID"

'Set the start value of the area and the end value and pass the area to this parameter. Rangeval.StartValue = 42rangeVal.endValue = 72Paramfield.currentVales.add (Rangeval) 'Add the second parameter to the parameter field collection. Paramfields.Add (paramfield)

'Place the parameter field into the viewer control. CrystalReportViewer1.ParameterfieldInfo = paramfields

CrystalReportViewer1.Reportsource = "C: / report / my report.rpt"

[C #] // The declaration passes the parameters to the variable required for the // viewer control. ParameterFields paramFields = new ParameterFields (); ParameterField paramField = new ParameterField (); ParameterDiscreteValue discreteVal = new ParameterDiscreteValue (); ParameterRangeValue rangeVal = new ParameterRangeValue ();

// The first parameter is a discrete parameter having a plurality of values.

/ / Set the name of the parameter field, it must / / and match the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer Name";

/ / Set the first discrete value and pass it to this parameter. Discreteval.Value = "AIC Childrens"; paramfield.currentVales.Add (Discreteval);

/ / Set the second discrete value and pass it to this parameter. // Discreteval variable is set to a new value, so that previous settings // will not be overwritten. Discreteval = new parameterdiscretevalue (); discreteval.value = "aruba sport"; paramfield.currentvalues.add (discreteval);

// Add this parameter to the parameter field collection. Paramfields.Add (paramfield);

// The second parameter is the zone value. PARAMFIELD variable // is set to a new value, so that the previous settings will not be overwritten. Paramfield = new parameterfield ();

/ / Set the name of the parameter field, it must / / and match the parameters in the report. PARAMFIELD.PARAMELDNAME = "Customer ID";

// Set the start value and end value of the range and pass the range to // this parameter. Rangeval.StartValue = 42; RangeVal.endValue = 72; paramfield.currentVales.add (Rangeval);

// Add the second parameter to the parameter field collection. Paramfields.Add (paramfield);

// Place the parameter field into the viewer control. CrystalReportViewer1.ParameterfieldInfo = paramfields;

[C ] // The declaration passes the parameters to the variable required for // viewer control. ParameterFields * paramFields = new ParameterFields (); ParameterField * paramField = new ParameterField (); ParameterDiscreteValue * discreteVal = new ParameterDiscreteValue (); ParameterRangeValue * rangeVal = new ParameterRangeValue (); // The first parameter is a parameter having a plurality of discrete values . / / Set the name of the parameter field, it must / / and match the parameters in the report. Paramfield-> ParameterfieldName = "Customer Name";

/ / Set the first discrete value and pass it to this parameter. String * Val = "AIC Childrens"; discreteval-> value = val; paramfield-> currentValues-> add (discreteval);

/ / Set the second discrete value and pass it to this parameter. // Discreteval variable is set to a new value, so that previous settings // will not be overwritten. Discreteval = new parameterdiscretevalue (); val = "aruba sport"; discreteval-> value = val; paramfield-> currentValues-> add (discreteval);

// Add this parameter to the parameter field collection. PARAMFIELDS-> Add (paramfield);

// The second parameter is the zone value. PARAMFIELD variable // is set to a new value, so that the previous settings will not be overwritten. Paramfield = new parameterfield ();

/ / Set the name of the parameter field, it must / / and match the parameters in the report. Paramfield-> parameterfieldname = "Customer ID";

// Set the start value and end value of the range and pass the range to // this parameter. Rangeval-> StartValue = __box (42); Rangeval-> endValue = __box (72); paramfield-> currentVales-> add (rangeval);

// Add the second parameter to the parameter field collection. PARAMFIELDS-> Add (paramfield);

// Place the parameter field into the viewer control. CrystalReportViewer1-> ParameterfieldInfo = paramfields;

CrystalReportViewer1-> EXPORTREPORT ();

转载请注明原文地址:https://www.9cbs.com/read-22488.html

New Post(0)