[Post] use Crystal Reports in ASP. NET

Source: Internet
Author: User
Before we studied Crystal Reports in vs. net, my friends and I were very curious about how to add this complicated stuff to our web application. A week later, after reading a large number of "Howto" documents, we successfully added some simple reports to our Asp.net Program And get some tips.

This articleArticleIt teaches you how to use Crystal Reports in. NET web applications, and also helps you avoid detours during your learning process. To get the best results, you 'd better have some basic ASP. NET database access knowledge and development experience using vs. net.

Introduction

Crystal Reports can be obtained in many ways, one of which is created using vs. net. It provides a rich set of models so that we can operate on attributes and methods at runtime. If you are using vs. Net to develop a. Net program, you do not need to install other software because it is already embedded in vs. net.

 Advantages:

Vs. NET Crystal Reports have the following main advantages:

    • Quick report development

    • Ability to export complex interactive charts

    • It can be used with other controls in webform.

    • Reports can be imported into multiple formats, such as. txt, xls, HTML, and RTF.

Structure:

Some components form a layer-2 structure of the crystal report. The following web applications are required:

Client:

The client only needs a browser that can access the reports embedded in the ASPX page.

Server:

Crystal Report Engine (crengine. dll ))

It can be used to complete some tasks, such as merging data in the report file and converting the report to another format. It is precisely because of the role of the Report Engine that the crystal report in ASP. NET can be converted into a common HTML format.

Crystal Report designer (crdesigner. dll ))

The crystal report is created in the designer. In the designer, you can design titles, insert data, formulas, charts, subreports, and so on.

. Rpt report file

The first step in executing the report is to create the Report on the interface of the Crystal Report designer. By default, Microsoft has provided some ready-made. rpt examples.

Data Source

The method for getting the. rpt file to the database depends on your method selection. You can choose to allow the Crystal Report to select data by yourself without using anyCodeAlternatively, you can manually assemble the dataset and then transmit it to the report file.

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

The crystal report display control is a webform control that can be viewed as a container for storing reports on the. ASPX page. Note: In some complex operations, the Report Server and the Web server may not be on the same physical host, and the Web server sends HTTP requests to the Report Server. Crystal Reports can also be executed as WebServices.

 Execution Mode

The following method can be used to retrieve data from a crystal report:

Pull Mode:

 When a request is sent, the crystal report directly connects to the database based on the specified driver and then assembles the data.

Push mode:

At this time, the development table has to write code to connect data and assemble dataset, and send it to the report. In this case, you can use the report to maximize performance by sharing connections and limiting the size of record sets.

Report Type:

The crystal report designer can directly include reports to projects and use independent report objects.

Stronugly-typed report:

When you add a report file to a project, it becomes a "stronugly-typed" report. In these cases, you will have the right to directly create report objects, which will reduce some code and provide some performance.

 Un-typed report:

The reports here are not directly included in the project, so they are called 'un-typed 'reports. In this case, you have to use the 'reportdocumi' object of the crystal report to create an instance and use the report manually.

Other considerations

Although the Crystal Report viewer has some cool functions, such as scaling and page navigation. However, it does not provide the printing function. You have to call the printing function of the browser.

If the Crystal Report in vs. NET is not registered, it can only be used for 30 times. After 30 times, the "save" function will no longer be used. To avoid this, you are not registering this product at http://www.crystaldecisions.com. (It seems that this is not the case. If you do not register, it may take a long time, but you cannot provide support)

By default, the installed crystal report supports only five users. To support more users, you have to purchase a license at http://www.crystaldecisions.com.

Let's take a look ---- use a ready-made crystal report file in Asp.net

 Let's first feel the feeling of Using Crystal Reports in webform.

1) drag the Crystal Report viewer control from the webform toolbar to the. ASPX page.

2) display the Properties window of the Crystal Report viewer Control

3) Click [...] to view the "Data Binding" attribute. The databinding window is displayed.

4) Select "report source" from the "Bindable attributes" area on the left"

5) Select the "custom binding expression" radio button and specify it in the window at the bottom of the right. rpt file name and path, for example: "C: \ Program Files \ Microsoft Visual Studio. net \ Crystal Reports \ samples \ reports \ General Business \ world sales report. RPT ", then" OK"

Note:: The "World sales report. rpt" file was created when vs. Net was installed. If you specify other directories during installation, you 'd better confirm the correctness of the path.

In the above steps, the following code is inserted into the ASP. NET file:

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

And:

<CR: crystalreportviewer>
Id = "crystalreportviewer1"
Runat = "server" width = "350px" Height = "50px"
Reportsource = '<% # "C: \ Program Files \ Microsoft Visual Studio. net \ Crystal Reports \ samples \ reports \ General Business \ world sales report. RPT "%> '>
</Cr: crystalreportviewer>

Note:: In the code automatically generated in the official vs. Net version of Apsara stack, the style generated by reportsource is not like this. It is:

Reportsource = "<% # c: \ XXXXX \ XXX. rpt %>"

The error message is displayed. There are two errors:

    • Databind must contain double quotation marks, so only single quotation marks can be used externally.
    • The directory separator cannot be "\", and must be "\\"

It must be manually modified according to the format described in this article. This is also a bug in vs. net.

6) Call the databind method in the page_load method. (The code is VB. NET)

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

Databind ()

End sub

7) Save and compile your page. Now you have a webform page with built-in Crystal Reports.

Note:In actual development, the inetsrv directory cannot be accessed at the beginning. The solution is to change the Security Attribute of the directory so that the user has writable permissions. Flying knife I found that the solution provided by the. NET system is useless, or it may be because I am using the Windows. Net operating system.

 

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.