Simple use of Crystal Reports in Asp.net

Source: Internet
Author: User

Crystal ReportsIt is an efficient report technology with powerful content creation and integration functions. It is a report tool developed by a third party. Using Crystal Reports, we can better present data to users. You can program the data in the dataset beforeWindowsApplicationProgramOrWebThe output in the application is displayed. However, if you want to perform more operations than the basic formatting, such as sum, average, multi-pole summary, and Icon creation, the output is complex, the crystal report just makes up for the shortcomings.

InWindowsApplications andWebWe can use Crystal Reports in applications, but inWindowsCrystal Reports in applicationsWebThe powerful functions in the application can easily implement the printing and export functions. Here we will only discussAsp.netIn the simple use of Crystal Reports.

Let's take a very simple example. CreateWebApplication, add toolbox on the pageWebIn the formButtonControl,CrystalreportviewerControls (this is the crystal report control) andHtmlUnderFile FieldControl.File FieldControls allow us to select a local file. to display a crystal report, we need a crystal report file with the suffixRPTThis file can be added by adding a new item. Now, if you already have a crystal report file, you can view it in the following steps.

I,Double-click the page to enterCodeEnvironment inPage_loadAdd the following code to the event:

If (session ["filename"]! = NULL)

Crystalreportviewer1.reportsource = session ["FILENAME"]. tostring ();

This code mainly stores the file name inSessionInPageloadTo avoid errors when refreshing the page.

II, InButtonClick the button to add the following code to the event:

String strname = file1.postedfile. filename;

If (strname. Trim ()! = ""){

Crystalreportviewer1.reportsource = strname;

Seesion ["filename"] = strname;

}

Then pressF5Run, select a readyRPTFile, click the button to view the report results displayed on the page.

The establishment of the crystal report file is important throughout the process. The creation of the crystal report includesPullAndPushTwo modes,PullThe mode is to directly specify the database driver and then assemble the data,PushIn this mode, you need to write your own code to connect to the database and upload them to the report,PushMode RatioPullMore flexible.

For space reasons, let's talk about it first.PullMode:

AddRPTFile, a dialog box will pop up, select as a blank report, and click OK.In "field resource manager" on the right, right-click "database Field" and choose "add or delete database". The database expert dialog box is displayed, and selectOledb (ADO)Create a database connection according to the wizard.

After establishing a database connection, you can add tables in the database to the report, and then drag the summary of the fields to be displayedRPTFile details, and the field name is automatically added in the header, this name can be changed according to your preferences.

This is a simple report. Of course, the report function is far more than that. You should write the code below.

1First, import the namespace

Using crystaldecisions. crystalreports. engine;

Using crystaldecisions. shared;

2After the namespace is imported,ReportDocumentClass Object:

ReportDocument reportdoc;

3FinallyPageloadAdd the following code to the event:OKNow

Reportdoc = new reportdoument ();

Reportdoc. Load (server. mpapath ("crystalreport. rpt "));

Crystalreportviewer1.reportsource = reportdoc;

PressF5Run the command to view the result.

Now, continue learning..........

Related Article

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.