Use crystal report (on) in Visual Studio. NET)

Source: Internet
Author: User
From www.aspfree.com
Translated by cash (World 7)
Cashcao@msn.com

Before we started this small study on how to use Crystal Reports on vs. net, my friends and I were talking about how to apply it to our webProgramAre very confused. A week later, after some efforts (search for the "how-to" document on the Internet), we learned some tips for adding simple reports to the Asp.net program.

This article includes the application of Crystal Report to your. net web application requires a summary of some of the methods, through these step-by-step demonstration, you will encounter errors (as we have encountered) will be minimized. To make better use of this article, readers should have basic knowledge about database connection in ASP. NET and are using vs. Net for development. Please note that we only use beta2 for the followingCodeA test was conducted.

This article includes the following content:

(1) Introduction;
(2) test tool-use an existing crystal report file on the. ASPX page;
(3) crystal report demonstration-use PULL model;
(4) demonstration of Crystal Report-use PUSH model;
(5) output the report file to other formats.

There are a variety of Crystal Reports. Here we use "Crystal Report for Visual Studio. NET" designed specifically for. net ". It is a rich programming model, which can operate its properties and methods. If you use vs. Net to develop your program, you do not need to install any additional software because it is already included in vs. net.

Advantages

The main advantages of using crystal report for Visual Studio. NET are:

-- Quick report development
-- Can be expanded to complex reports with associated charts
-- It can interact with other controls in the web form.
--It can be output to common formats such as .20.,.doc,.xls,.html and. rtf.

Overall Structure

Display the crystal report with a two-layer structure:

Client:

The client only needs to use a browser to obtain the report loaded on the. ASPX page.

Server:

-Crystal Report Engine (crengine. dll)

Together with other tasks (such as merging data and report files, and outputting data in different formats), the Crystal Report engine can convert your crystal report to upload. simple HTML in the ASPX page.

-Crystal Report designer (crdesigner. dll)

You can use crystal report designer to create reports from the beginning. You can design titles, insert data, formulas, tables, and subreports.

-The. rpt report file
The first step in applying a report to your web application is to use crystal report designer to create a report. You already have some ready-made samples on your computer, so you can use them now.

-The data source

The way the. rpt file obtains data depends on the method you choose. You can choose to create a crystal report to obtain data without writing any code manually. You can also choose to bind your dataset and import it to the report file. We will see different applications later.

-Crystal Report viewer web form control (crwebformviewer. dll)

Crystal Report viewer is a web form control that can be inserted into the. ASPX page. It can be understood as a container that contains reports.

Note: In the complex implementation process, the report server and the network server can be located on different servers. In this case, the network server will request the Report Server. Crystal Report will be executed as a web service.

Execution Mode

Execute any of the following methods to obtain the crystal report data.

Pull Model)

In the PULL model, the driver connects to the database and pulls in the data as needed. When using this model, the connection to the database and the SQL commands executed to obtain data are both processed by Crystal Reports, and developers do not need to write code. If you do not need to write any special code at runtime, use the PULL model.

Push Model)

On the contrary, the pushing model requires developers to write code to connect to the database, execute SQL commands to create a record set or dataset that matches the fields in the report, and pass the object to the report. This method allows you to place the connection share in the application and filter the data before Crystal Reports receives the data.

Report Type

In addition to report independent from the solution, crystal report designer can also load reports contained in the solution.

-Stronugly-typed report:

When a report is added to the solution, the report becomes a strongly-typed report. In this case, you can directly create a report instance (which can reduce some code) and hide it. Of course, you can click "show all files" in Solution Explorer to display it.

-Un-typed report:

A report that is not included in the plan is a UN-typed report. In this case, you must create a 'report document' object for the crystal report engine and manually load the report.

Other things you should know:

Although the Crystal Report viewer control has built-in options such as zooming and page navigation, it does not have built-in printing options. You must use the print option of the browser.

Crystal Report for Visual Studio. NET unregistered version only available in the first 30 features. After that, the SAVE option cannot be used. You have to pay for all functions.

By default, only the licenses of five users are available. To support more users, you must purchase an additional license from www.crystaldecisions.com.

Test Tool-use an existing crystal report file on the. ASPX page
Now let's take a look at how to apply a crystal report file to your web form.

(1) drag a "Crystal Report viewer" from the tool box and place it on your. ASPX page.

(2) Open the Properties window of this control.

(3) Click [...] on the "Data Binding" attribute to bring up the data binding window.

(4) Select "report source" from the left ".

(5) Select "custom binding expression" and enter the following statement in the form below:

"C: \ Program Files \ Microsoft Visual Studio. Net \ Crystal Reports \ samples \ reports \ General Business \ world sales report. rpt"

Remember to include quotation marks and click OK.

Note: The 'World sales report. rpt' file is installed as part of vs. net. If you have specified a different path to install vs. net, modify it on your own.

Note: C # enter the following string: "C: \ Program Files \ Microsoft Visual Studio. net \ Crystal Reports \ samples \ reports \ General Business \ world sales report. RPT ")

After loading for a short time, you will see a simple preview.

The above steps actually Insert the following code on your. ASPX page:

<% @ Register tagprefix = "cr" namespace = "crystaldecisions. Web" assembly = "crystaldecisions. Web" %>

And

<CR: crystalreportviewer

Id = "crystalreportviewer1"

Runat = "server"

Width = "350px" Height = "50px"

Reportsource = ''>

</Cr: crystalreportviewer>

(6) Call the databind method and edit the page load event in the code behind file.

Private sub page_load (byval sender as system. Object, byval e as system. eventargs)

Databind ()

End sub

(7) Save, generate and run. Now you have a page containing the crystal report file.

This article is reproduced from the Chinese software (http://www.csdn.net ).

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.