Use crystal report in Visual Studio. NET

Source: Internet
Author: User

Before we startVs. netUse onCrystal ReportsBefore a small research, my friends and I were both concerned about how to apply it to ourWebProgramAre very confused. A week later, after some efforts(Find"How-"Documentation)We have mastered how to add simple reportsAsp.netSome tips in the program.

This article includesCrystal ReportApply to your. NET webSummary of the methods required by the application. Through these step-by-step demonstrations, you will encounter errors(As we once met)It will be minimized. To make better use of this article, readers shouldASP. NETBasic knowledge about database connection, and is usingVs. netDevelopment. Please note that we only useBeta2For the followingCodeA test was conducted.

This article includes the following content:

(1)Introduction;

(2)Knife test-in. AspxUse an existingCrystal ReportFile;

(3)Crystal ReportDemo-UsePull model;

(4)Crystal ReportDemo-UsePush model;

(5)SetReportFile output to other formats.

There are a varietyCrystal ReportHere, we use. NetDesigned"Crystal Report for Visual Studio. NET". It isRich Programming ModelTo operate on it.PropertiesAndMethods. If you useVs. netTo develop your program, you do not need to install any additional software because it is already included inVs. net.

Advantages
UseCrystal Report for Visual Studio. NETThe main benefits include:

-- Quick report development
-- Can be expanded to complex reports with associated charts
-- Can be associated with thisWeb formOther controls in
-- Can output it as a common. PDF,. Doc,. Xls,. Html,. RtfOther formats

Overall Structure

Demonstrate this two-layer structureCrystal ReportRequired:

 Client:

The client can be mounted. AspxReports on the page.

Server:

-Crystal Report Engine (crengine. dll)

Together with other tasks (such as merging data and report files, and outputting data in different formats,Crystal Report EngineYou canCrystal ReportTransfer. AspxSimple and clearHTML.

-Crystal Report designer (crdesigner. dll)

UseCrystal Report designerYou can create reports from the beginning. You can design titles, insert data, formulas, tables, and subreports.

-The. rpt report file

Apply a report to yourWebThe first step in the application is to useCrystal Report designerCreate a report. You already have some ready-made samples on your computer, so you can use them now.

The Data Source

. RptThe method for obtaining data from a file depends on the method you choose. You can choose to makeCrystal ReportTo obtain data without writing any code, you can also choose to bind yourDatasetAnd pass it into the report file. We will see different applications later.

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

Crystal Report ViewerIs. AspxPageWeb form Control. 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 ReportAsWeb ServiceExecuted.

Execution Mode

Execute any of the following methods to obtainCrystal ReportData.

Pull model (Pull Model)

In the PULL model, the driver will connect to the database and set the data as needed"Pull"Come in. When using this model, the connection to the database andSQLAll commands are composedCrystal ReportsIt does not require developers to write code. If you do not need to write any special code at runtime, use the PULL model.

Push model (Push Model)

On the contrary, the pushing model requires developers to write code to connect to the database and executeSQLCommand 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 andCrystal ReportsFilter the data before receiving the data.

Report Type

In addition to the report that is independent from the solution,Crystal Report designerYou can also load reports that are included in the solution.

Stronugly-typed report:

When a report is added to the solution, the report becomesStronugly-typed report. In this case, you can directly create a report instance (which can reduce some code) and hide it. Of course you can clickSolution ExplorerIn"Show All Files"To display it.

-Un-typed report:

Reports that are not included in the solution areUn-typed report. In this case, you must createCrystal Report EngineOf'Report document'And manually load the report.

Other things you should know:

AlthoughCrystal Report ViewerBuilt-in controlsZooming,Page navigationBut it does not have the built-in print option. You must use the print option of the browser.

Crystal Report for Visual Studio. NETUnregistered version only before30Item. After thatSave OptionIt cannot be used. You have to pay for all functions.

The default installation only provides licenses for five users. To support more users, you mustWww.crystaldecisions.comPurchase additional licenses.

Knife test-in. AspxUse an existingCrystal ReportFile

Now let's see howCrystal ReportApply the file to yourWeb form.

(1)SlaveTool BoxDrag"Crystal Report viewer"Put it in your. AspxPage.

(2) Open thisControlProperties window.

(3) In"Data Binding"Click on Properties[...]Pop-upData BindingWindow.

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

(5)Select"Custom binding expression", 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, pointsOK.

Note:'World sales report. rpt'File is usedVs. net. If you specify a different path for installationVs. net,Please modify it by yourself.

(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 are actually in your. AspxThe following code is inserted on the page:

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

And<Form>Section

<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>

(6)CallDatabindMethod, inCode behindEdit in filePage load event

Private SubPage_load (ByvalSenderAsSystem. object,ByvalEAsSystem. eventargs)

Databind ()

End Sub

(7 ). Save, generate, and run. Now you haveCrystal ReportFile page.

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.