Before we conducted research on the Crystal Reports in VS.NET, I and my friend had a very curiosity of how to join this complex stuff to our web app. After a week, after reading a large number of "Howto" documents, we successfully added some simple report to our ASP.NET program and got some small decisions.
This article teaches you how to use crystal reports in .NET web applications, you can also let you take less detours during your study. In order to get the best results, readers should best have some basic ASP.NET access to database knowledge and experience using VS.NET.
Introduction
Crystal reports can be obtained from a number of methods, one is to create using VS.NET, which provides a very rich model to operate attributes and methods at runtime. If you are using VS.NET development .NET program, you don't need to install other software, because he is already in vs.net.
advantage:
The vs.net crystal statement has some of the main advantages:
· Quick report development
· Can derive complex interactive charts
· Can be used in WebForm with other controls
· Export the report to a variety of formats such as .pdf, .doc, xls, html, rtf.
structure:
Some components form a two-layer structure of the crystal report, and the web applications needed:
Client:
The client only requires an auditor that can access the embedded ASPX page report.
Server:
Crystal Report Engine (Crengune.dll))
Through it can complete some tasks, such as merging data in the report file, the conversion report is other formats. It is also because of the role of the report engine, the Crystal Report in ASP.NET can be converted into ordinary HTML format.
Crystal Report Designer (CRDESigner.dll)
The crystal report is created in the designer, in the designer you can design the title, insert data, formula, chart, sub-report, etc.
.rpt report file
The first step in the implementation report is to create this report at the Crystal Report Designer interface, and Microsoft has provided some ready-made .rpt examples in the default installation.
Data Source
The way the .rpt file acquisition database depends on your method's choice, you can choose to make the crystal report you choose to select the data yourself without any code or you can also select manually assembled DataSet, and then transfer it to the report file.
Crystal Report View Control (Crystal Report Viewer Web Form Control (CRWEBFORMVIEWER.DLL))
Crystal Report View control is a WebForm control that can be regarded as a container that stores reports in the .aspx page. Note: In some complex operations, the report server and the web server may not be on the same physical host, the web server transmits the HTTP request to the report server. Crystal reports can also be performed when WebService is performed.
Execution mode
Crystal report data can be implemented using the following method:
PULL mode:
When the request is requested, the crystal report directly connects the database directly to the database and assembles this data.
PUSH mode:
At this time, the development table has to write code connection data and assemble the DataSet, and transfer it to the report. In this case, by using connection sharing and limiting the size of the record set, the report performance can be maximized.
Report type:
Crystal Report Designers can directly contain reports to engineering and can use separate report objects.
Strongly-type report:
When you add the report file to the project, it turns into a "strongly-type" report. In these cases, you will have the power to create the object of the report, which will reduce some code and provide some performance. UN-TYPED report:
The report here is not directly included in the project, so it is called the 'UN-TYPED' report. In this case, you have to establish an instance using the "ReportDocuemt" object of the crystal statement, and "manual" manual apipe.
Other considerations
Although the Crystal Report Viewer has some cool features, such as zoom, page navigation, etc. But he does not provide print function, you have to call the printed function of the visitors.
Crystal Report in VS.NET If not registered, then it can only use 30 times, 30 times, "save" can not be used again. To avoid this, you are not in http://www.crystaldecisions.com/ here. (It seems that it is not a case, it seems that it can be used for a long time, but it is not supported)
The default installed crystal report can only support 5 users, in order to support more users, you have to purchase licenses in http://www.crystaldecisions.com/.
Let us feel it ---- use a ready-made crystal report file in ASP.NET
Let us feel the feeling of using crystal reports in WebForm.
1) Drag the Crystal Report Viewer from the WebForm toolbar to the .aspx page.
2) Match the properties window of the Crystal Report Viewer Control
3) Click the [...] button to view the "Data Binding" property and pop up the DataBinding window.
4) Select "Report Source" from the "Bindable property" area of the left.
5) Select the "Custom Binding Expression" radio button, specify the file name and path of the.rpt file in the window on the bottom of the right, for example: "C: // Program Files // Microsoft Visual Studio.Net//crystal Reports // Samples // Reports // General Business // World Sales Report.rpt ", then" OK "
Note: The file "World Sales Report.rpt" file is created during VS.NET installation. If you specify another directory during the installation process, you'd better confirm the correctness of the path.
The above steps is actually inserted into the following code to the ASP.NET file:
<% @ Register tagprefix = "cr" namespace = "crystaldecisions.web" assembly = "crystaldecisions.web"%>
as well as:
Reportsource = "<% # c: /xxxxx/xxx.rpt%>"
This is wrong, there will be an error message, there are two errors:
There are double quotes in Database, so you can only use single quotes outside.
Directory separation symbols cannot be used, "//" must be used
You must manually modify it in accordance with the format described in this article, which is also a BUG of VS.NET.
6) Call the DataBind method in the Page_Load method. (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 for embedded crystal reports.
Note: In the actual development, an error that cannot be accessed in the INETSRV directory will appear at the beginning, and the solution is to change the security properties of its directory, so that the user user has writable permissions. Flying knife I found that the solution from the .NET system has been useless, or it may be the reason I use the Windows.NET operating system.