Crystal Report Transmission Parameters and formula Parameters

Source: Internet
Author: User
Passing parameters and using formula PARAMETERS TO THE CRYSTAL REPORT
The following describes how to pass string type parameters and numeric parameters to the Crystal Report, and use formula parameters for calculation and conversion.

Read more articles related to the Crystal Report on this site:
Crystal Report formulas must be read (use of crystal report formulas)
Crystal Report Transmission Parameters and formula Parameters
Three classic crystal report Designs
Four Web printing methods for Crystal Reports
Display any specified FIELD IN THE CRYSTAL REPORT
Asp. Net and Crystal Report (Crystal Report)
PASS Parameters to the crystal report, set parameters in the crystal report, and then assign the parameters to the Selection Formula

CrystalDecisions. Shared. ParameterValues mypaVal = new CrystalDecisions. Shared. ParameterValues ();
CrystalDecisions. Shared. ParameterDiscreteValue mypaDVal = new CrystalDecisions. Shared. ParameterDiscreteValue ();
MypaDVal. Value = parameter Value;
MypaVal. Add (mypaDVal );
Myrep. DataDefinition. ParameterFields [\ "parameters in the crystal report \"]. ApplyCurrentValues (mypaVal );

Step 1: generate the dataset DataSet1.xsd and connect to the database. This is detailed in "Crystal report printing 2", which is not described here.
Step 2: Add a blank crystal report CrystalReport1.rpt. In field resource manager, right-click "parameter field" and choose "add". Here we name it p1 (Value Type: string ), p2 (the value type is a number and the value is set to a region value). For example, do not modify other values.
(Fig. 3.1)
Right-click "formula field", select "new", and create two new ones: f1 and f2. After confirmation, the "formula Editor" will appear. For example, do not change it first, save it, and close it.
(Fig. 3.2)
Step 3: Drag p1 and p2 to the report and save the report.
Step 4: write the code. In WebForm1.aspx, write the following code with CrystalReportViewer1 as the object: // declare to pass the parameter
// Variables required by 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 with multiple values.
// Set the name of the parameter field, which must
// Match the parameters in the report.
ParamField. ParameterFieldName = \ "p1 \";

// Set the first discrete value and pass it to this parameter.
DiscreteVal. Value = \ "dongliang \";
ParamField. CurrentValues. Add (discreteVal );

// Set the second discrete value and pass it to this parameter.
// The discreteVal variable is set as a new value. In this way, the previous settings
// It will not be overwritten.
DiscreteVal = new ParameterDiscreteValue ();
DiscreteVal. Value = \ "DONGLIANG \";
ParamField. CurrentValues. Add (discreteVal );

// Add this parameter to the parameter field set.
ParamFields. Add (paramField );

// The second parameter is the region value. ParamField variable
// Is set as the new value, so that the previous settings will not be overwritten.
ParamField = new ParameterField ();

// Set the name of the parameter field, which must
// Match the parameters in the report.
ParamField. ParameterFieldName = \ "p2 \";

// Set the start value and end value of the range and pass the range
// This parameter.
RangeVal. StartValue = 42;
RangeVal. EndValue = 72;
ParamField. CurrentValues. Add (rangeVal );

// Add the second parameter to the parameter field set.
ParamFields. Add (paramField );

// Put the set of parameter fields into the viewer control.
CrystalReportViewer1.ParameterFieldInfo = paramFields;
Rpt = new CrystalReport1 ();
CrystalReportViewer1.ReportSource = rpt;

You still need to reference the namespace:
Using CrystalDecisions. Shared;
Using CrystalDecisions. CrystalReports. Engine;

Rpt is ReportDocument rpt;
The above describes the parameter fields. The following describes how to use the formula field to process the added parameter fields:
Step 5:
Drag the formula field f1 into the crystal report and right-click it and select "edit formula". For example, in Figure 3.2, select the string processing function as follows: Left ({? P1}, 5)
(Fig. 3.3)
Other numbers are processed Similarly, such:

(Fig. 3.4)
Finally:
Run, you will see:


(Fig. 3.5)
Successful!

How do I transmit parameters to the stored procedure in the crystal report data source?
The crystal report automatically creates a "parameter field" for each "parameter in the stored procedure", which becomes a problem of parameter assignment during runtime ......

Custom parameter field during runtime

[Visual Basic] 'declares that parameters are passed
'Variables 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 with multiple values.

'Set the parameter field name, which must
'Is consistent with the parameters in the report.
ParamField. ParameterFieldName = \ "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 as a new value. In this way, 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 set.
ParamFields. Add (paramField)

'The second parameter is the region value. ParamField variable
'Is set as the new value, so that the previous settings will not be overwritten.
ParamField = New ParameterField ()

'Set the parameter field name, which must
'Is consistent with the parameters in the report.
ParamField. ParameterFieldName = \ "Customer ID \"

'Set the start and end values of the region and pass the region to this parameter.
RangeVal. StartValue = 42
RangeVal. EndValue = 72
ParamField. CurrentValues. Add (rangeVal)

'Add the second parameter to the parameter field set.
ParamFields. Add (paramField)

'Place the set of parameter fields into the viewer control.
CrystalReportViewer1.ParameterFieldInfo = paramFields

CrystalReportViewer1.ReportSource = \ "c: reportsmy report. rpt \"

[C #]
// Declare to pass the parameter
// Variables required by 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 with multiple values.

// Set the name of the parameter field, which must
// Match the parameters in the report.
ParamField. ParameterFieldName = \ "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 as a new value. In this way, the previous settings
// It will not be overwritten.
DiscreteVal = new ParameterDiscreteValue ();
DiscreteVal. Value = \ "Aruba Sport \";
ParamField. CurrentValues. Add (discreteVal );

// Add this parameter to the parameter field set.
ParamFields. Add (paramField );

// The second parameter is the region value. ParamField variable
// Is set as the new value, so that the previous settings will not be overwritten.
ParamField = new ParameterField ();

// Set the name of the parameter field, which must
// Match the parameters in the report.
ParamField. ParameterFieldName = \ "Customer ID \";

// Set the start value and end value of the range and pass the range
// This parameter.
RangeVal. StartValue = 42;
RangeVal. EndValue = 72;
ParamField. CurrentValues. Add (rangeVal );

// Add the second parameter to the parameter field set.
ParamFields. Add (paramField );

// Put the set of parameter fields into the viewer control.
CrystalReportViewer1.ParameterFieldInfo = paramFields;
[C ++]
// Declare to pass the parameter
// Variables required by 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 with multiple values.
// Set the name of the parameter field, which must
// 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.
// The discreteVal variable is set as a new value. In this way, the previous settings
// It will not be overwritten.
DiscreteVal = new ParameterDiscreteValue ();
Val = \ "Aruba Sport \";
DiscreteVal-> Value = val;
ParamField-> CurrentValues-> Add (discreteVal );

// Add this parameter to the parameter field set.
ParamFields-> Add (paramField );

// The second parameter is the region value. ParamField variable
// Is set as the new value, so that the previous settings will not be overwritten.
ParamField = new ParameterField ();

// Set the name of the parameter field, which must
// Match the parameters in the report.
ParamField-> ParameterFieldName = \ "Customer ID \";

// Set the start value and end value of the range and pass the range
// This parameter.
RangeVal-> StartValue = _ box (42 );
RangeVal-> EndValue = _ box (72 );
ParamField-> CurrentValues-> Add (rangeVal );

// Add the second parameter to the parameter field set.
ParamFields-> Add (paramField );

// Put the set of parameter fields into the viewer control.
CrystalReportViewer1-> ParameterFieldInfo = paramFields;

CrystalReportViewer1-> ExportReport ();

Read more articles related to the Crystal Report on this site:
Crystal Report formulas must be read (use of crystal report formulas)
Crystal Report Transmission Parameters and formula Parameters
Three classic crystal report Designs
Four Web printing methods for Crystal Reports
Display any specified FIELD IN THE CRYSTAL REPORT
Asp. Net and Crystal Report (Crystal Report)

Crystal Report Transmission Parameters use the crystal report formula parameters to pass parameters to the stored procedure in the Crystal Report Data Source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.