[Posting] Passing PARAMETERS TO THE CRYSTAL REPORT

Source: Internet
Author: User

Reference --
Http://imar.spaanjaars.com/QuickDocID.aspx? Quickdoc = 310
Http://www.cddotnet.com/bbs/dispbbs.asp? Boardid = 3 & id = 3 & star = 1 #4
Http://community.csdn.net/Expert/topic/3512/3512093.xml? Temp =. 3724787.

How to pass parameters to crystalreportviewer and reportdocument ......
1. crystalreportviewer
Use the crystalreportviewer. parameterfieldinfo attribute ......
1. crystalreportviewer Member
Public instance attributes
Parameterfieldinfo (inherited from crystalreportviewerbase) parameterfields. Obtains or sets a set of parameter fields.
2. reportdocument
Use the reportdocument. datadefinition. parameterfields attribute ......
1. reportdocument Member
Public instance attributes
Datadefinition. Obtain the datadefinition object.
2. datadefinition Member
Public instance attributes
Parameterfields parameterfielddefinitions. Obtain the parameterfielddefinitions set.
Iii. Custom parameter field during running (crystalreportviewer)
Refer:
Set parameters | binding options for Windows form viewer | binding options for web form Viewer

You can enter parameters in the crystal report. This parameter has multiple purposes. For example:
The parameter is based on the database field and allows you to specify the value of this field to filter data in the report.
Use the parameter field to apply the condition format to the report.
Use parameter fields to define the sorting order.
The following example shows how to useCodeSet the parameter field value. This example explains how to set two different parameters: the first is a multi-value discrete parameter, and the second is a region value parameter.

Modify parameter fields during runtime

[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;

The crystal report version is 9.2, and the background is sqlserver 2000. The report data source is a stored procedure with two parameters.
No matter what parameters I upload, the results of the report are all results in the development environment of the Crystal Report. The parameters are not included at all.
Please help me to see where the problem is
Below is the code
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using crystaldecisions. crystalreports. engine;
Using crystaldecisions. shared;
Namespace erpreports
{
/// <Summary>
/// Summary description for webform1.
/// </Summary>
Public class webform1: system. Web. UI. Page
{
Protected crystaldecisions. Web. crystalreportviewer crystalreportviewer1;
Mrb_pnper RPT;
Parameterfields crparameterfields;
Parameterfield crparameterfield;
Parametervalues crparametervalues;
Parameterdiscretevalue crparameterdiscretevalue;

Private void page_load (Object sender, system. eventargs E)
{
// Put user code to initialize the page here
}

# Region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
RPT = new mrb_pnper ();
Crystalreportviewer1.reportsource = RPT;

// Get the collection of parameters from the report
Crparameterfields = crystalreportviewer1.parameterfieldinfo;

Crparameterfield = crparameterfields ["@ begindate"];
Crparametervalues = crparameterfield. currentvalues;
Crparameterdiscretevalue = new parameterdiscretevalue ();
Crparameterdiscretevalue. value = request. querystring ["begindate"];
Crparametervalues. Add (crparameterdiscretevalue );

Crparameterfield = crparameterfields ["@ enddate"];
Crparametervalues = crparameterfield. currentvalues;
Crparameterdiscretevalue = new parameterdiscretevalue ();
Crparameterdiscretevalue. value = request. querystring ["enddate"];
Crparametervalues. Add (crparameterdiscretevalue );
Crystalreportviewer1.parameterfieldinfo = crparameterfields;

}

/// <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion
}
}

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.