Use Crystal Report in Visual Studio .NET (middle)

zhaozj2021-02-17  49

Use Crystal Report in Visual Studio .NET (middle)

From www.aspfree.comTranslated by Cash (Tianxia Seventh) Cashcao@msn.com

Crystal Report Demo - Using Pull Model we can use the following steps to implement the use of Crystal Reports:

(1) Create a .rpt file, set the necessary database coupons.

(2) Place the CrystalReportViewer Control on the .aspx page, set its properties to the.rpt file we created. Rpt file.

(3) Call the DataBind method in your Code Behind page file.

Create a .rpt file:

1) Right-click Solution Explorer, select "Add" -> "Add New Item" -> "Crystal Report", add a new Crystal Report file.

2) In the "Crystal Report Gallery" pop-up window, select the "AS A Blank Report" button and click "OK".

3) This will open a new report file on Crystal Report Designer

4) Right-click on the "Details Section" of the report and select "Database" -> "Add / Remove Database".

5) In the "Database Expert" window, expand the OLE DB (ADO "option, a new" OLE DB (ADO) window will open.

6) In the OLE DB (ADO "window, select" Microsoft Ole DB Provider for SQL Server "and click" Next ".

7) The specified connection information is as follows:

Server: HomePC (your server name)

User ID: SA

PASSWORD:

Database: PUBS: PUBS

8) Click "Next", Finish.

9) Now you can see Database Expert Display this table is selected.

10) Expand the "PUBS" library, expand "Tables", select the "Stores" table and ">" to include "SELECTED TABLES".

11) Now Field Explore will be displayed in "Database Fields".

12) Drag the desired fields to the Details section in the table. The name of this field will automatically appear in the Page Header section. If you want to change the Header's text, right-click the text of the Page Header section, select "Edit Text Object" and edit.

13) Save, we will use it later.

Create a Crystal Report Viewer Control

14) Return to our Web Form page, drag a "Crystal Report Viewer" Control to the page from "WebForms" Tool Box.

15) Select DataBindings in the Properties window and click [...]

16) In the Crystal Report Viewer DataBinding window, select "Report Source", select "Custom Binding Expression", type the path to the.rpt file you just saved (pay attention to double quotes).

17) Now you can see that Crystal Report Viewer shows a preview. Note: In the previous example, the Crystal Report Viewer control can display data directly because this report is saved with the data. However, in this example, it will not be displayed directly when design, because this report does not contain relevant data, replaced by the designed pseudo data, only when the running data is displayed.

Change BEHIND PAGE code

18) Open the Code Behind file and join the Database in the Page Load event.

run

19) Press F5 to run the viewing effect.

Note that you can use controls that come with this REPORT like "Page Navigation", "ZOOM".

转载请注明原文地址:https://www.9cbs.com/read-28487.html

New Post(0)