PASS Parameters TO THE CRYSTAL REPORT

Source: Internet
Author: User
Recently I made a little thing, and I want to use print-data output, so I want to use a crystal report. Let's talk about the crystal report. This stuff is really good. The function is very powerful, especially for the output format, almost meets the vast majority of requirements in the work. Flexible and easy to use. I will not go into details about specific technical things. If you are interested, you can go to some books to see them. I use CRYSTAL REPORT 10. It is relatively simple to connect to a database in a report. Now let's take a look at how to allow the report to dynamically accept parameters and then form a report file, this may be used in many practical scenarios. The front-end technology I used is ASP. NET. Let's take a look at some APIs about the crystal report parameters in. Net: parameterfields, parameterfield, parameterdiscretevalue, and parameterrangevalue. For specific usage of these APIs, refer to msdn. Also note that the following namespace should be added when using these classes: Using crystaldecisions. crystalreports. engine;
Using crystaldecisions. shared;
Next let's take a look at the specific code: # region -------------- pass the parameter -------------------- parameterfields parafields = new parameterfields () to the report ();
Parameterfield [] parafield = new parameterfield [8];
Parameterdiscretevalue [] discretevalue = new parameterdiscretevalue [8];
Parameterrangevalue rangevalue = new parameterrangevalue (); parafield [0] = new parameterfield ();
Parafield [0]. parameterfieldname = "name ";
Discretevalue [0] = new parameterdiscretevalue ();
Discretevalue [0]. value = (string) session ["name"];
Parafield [0]. currentvalues. Add (discretevalue [0]); parafield [1] = new parameterfield ();
Parafield [1]. Name = "majorname ";
Discretevalue [1] = new parameterdiscretevalue ();
Discretevalue [1]. value = (string) session ["majorname"];
Parafield [1]. currentvalues. Add (discretevalue [1]); parafield [2] = new parameterfield ();
Parafield [2]. Name = "yearname ";
Discretevalue [2] = new parameterdiscretevalue ();
Discretevalue [2]. value = (string) session ["yearname"];
Parafield [2]. currentvalues. Add (discretevalue [2]); parafield [3] = new parameterfield ();
Parafield [3]. Name = "tuitionpay ";
Discretevalue [3] = new parameterdiscretevalue ();
Discretevalue [3]. value = convert. todecimal (session ["tuitionpay"]);
Parafield [3]. currentvalues. Add (discretevalue [3]); parafield [4] = new parameterfield ();
Parafield [4]. Name = "tuitionowed ";
Discretevalue [4] = new parameterdiscretevalue ();
Discretevalue [4]. value = convert. todecimal (session ["tuitionowed"]);
Parafield [4]. currentvalues. Add (discretevalue [4]); parafield [5] = new parameterfield ();
Parafield [5]. Name = "year ";
Discretevalue [5] = new parameterdiscretevalue ();
Discretevalue [5]. value = (string) session ["year"];
Parafield [5]. currentvalues. Add (discretevalue [5]); parafield [6] = new parameterfield ();
Parafield [6]. Name = "month ";
Discretevalue [6] = new parameterdiscretevalue ();
Discretevalue [6]. value = (string) session ["month"];
Parafield [6]. currentvalues. Add (discretevalue [6]); parafield [7] = new parameterfield ();
Parafield [7]. Name = "day ";
Discretevalue [7] = new parameterdiscretevalue ();
Discretevalue [7]. value = (string) session ["day"];
Parafield [7]. currentvalues. Add (discretevalue [7]);

Foreach (parameterfield PF in parafield)
{
Parafields. Add (PF );
}

ReportDocument rptdoc = new reportdocument ();
Rptdoc. Load (server. mappath ("../agreementtest. rpt "));
This. crystalreportviewer1.reportsource = rptdoc;
This. crystalreportviewer1.parameterfieldinfo = parafields;
This. crystalreportviewer1. databind ();
// This. crystalreportviewer1. refreshreport ();
# Endregion: You must create these parameters in the crystal report before you can use them (and the parameters in the report are consistent with those in the Code ). In addition, you can choose to create a discrete value parameter (discrete) or create a continuous value parameter (range) when creating parameters in the crystal report 10 ), different classes (parameterdiscretevalue and parameterrangevalue) are used in the corresponding code ).

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.