Experience in using Crystal Reports 1-the first step in creating a crystal report and the most error-prone solution for compilation and the method for converting a report to a PDF document for Printing

Source: Internet
Author: User

Initial use of Crystal Reports (integrated with vs. net2003, version = 9.1.5000.0)

After installation, You need to register the registration number: 6707437608 password: aap5gks?gde100ds

To use a crystal report in The. aspx File

1. First create a file webform1.aspx and drag the component crystalreportviewer to generate code.

2. Create the file crystalreport1.rpt in the same folder of the project? In the field Resource Manager database Field "add Database", use oledb to connect to select the data table you want to display in the report (with a wizard)

3. The main code in webform1.aspx. CS is as follows:

Protected crystaldecisions. Web. crystalreportviewer crystalreportviewer1;

Private void page_load (Object sender, system. eventargs E)


// Place user code here to initialize the page

Tablelogoninfo logoninfo = new tablelogoninfo ();

ReportDocument orpt = new reportdocument ();

String rptdir = "f :\\ BBS \ test \ crystal \ crystalreport1.rpt"; // the absolute path of the crystalreport1.rpt File

Orpt. Load (rptdir );

// Set the logoninfo parameter. If not set here? During compilation, the "Login Failed" error is the easiest!

Logoninfo. connectioninfo. servername = "server name ";

Logoninfo. connectioninfo. databasename = "Database Name ";

Logoninfo. connectioninfo. userid = "username ";

Logoninfo. connectioninfo. Password = "password ";

Orpt. database. Tables [0]. applylogoninfo (logoninfo );

// Establish a connection between the. rpt file and the crystalreportviewer File

Crystalreportviewer1.reportsource = orpt;


4. // generate a PDF document and add it to the above Code

Exportoptions crexportoptions = new exportoptions ();

Diskfiledestinationoptions crdiskfiledestinationoptions = new diskfiledestinationoptions ();

Crdiskfiledestinationoptions. diskfilename = "F: \ BBS \ test \ crystal \ crystalreport1.pdf ";

Crexportoptions = orpt. exportoptions;

Crexportoptions. destinationoptions = crdiskfiledestinationoptions;

Crexportoptions. exportdestinationtype = exportdestinationtype. diskfile;

Crexportoptions. exportformattype = exportformattype. portabledocformat;

Orpt. Export ();

Orpt. Close ();

5. // read the exported report content and upload it to the client? Continue to add the following code

Response. clearcontent ();

Response. clearheaders ();

Response. contenttype = "application/pdf ";

Response. writefile ("F: \ BBS \ test \ crystal \ crystalreport1.pdf ");

Response. Flush ();

Response. Close ();?


The above is my usage summary. please correct me if there is anything wrong or can be improved !!!

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.