Crystal report summary

xiaoxiao2021-03-06  49

Crystal report is an excellent report development tool. When you develop a general management system, all reports use crystal reports. It is simple, easy to use and powerful, and the author is loved, and the use of crystal reports will be presented to everyone.

First, when using the own crystal report, please register, otherwise you can only use 30 times.

Crystal Report Registration Code Registration Number: 6707437608 Password: AAP5GKS0000GDE100DS

Second, use CrystalReportViewer to preview

The CrystalReportViewer control allows you to view Crystal Report in your application. The ReportSource property is used to set which report to see. After this property setting, the report is displayed in the viewer. The source of the report can be the pathDocument, the path of the report file, or a strong type report.

1. Open Toolbox and drag a CrystalReportViewer to the form and we name RPTVEW.

2. Adjust the Windows Form View to the desired size and move it to the desired position by dragging operation.

3. When running the application, the report will be displayed in the viewer.

Third, create new reports

1. Point "Add" and click Add New Item.

2. In the Add New Items dialog box, select Crystal Report from the Template area, name RPTClient, click Open.

3. In the Crystal Report library, choose one of the following options:

· Use report experts - Guide you to complete the creation process of the report and add your choice to Crystal Report Designer.

· As a blank statement - open the Crystal Report Designer.

· From the existing report - create a new report, which is the same as the designated other report.

Note that the Crystal Report library contains many experts to guide you to complete the creation of several specific types of reports. You may want to use an expert to create an initial report to determine which report construct method is suitable for your needs.

4. Click the "OK" button.

If you choose to use the Report Expert, the Report Experts dialog box appears and has a data resource manager. Select the required data for each folder, complete the operations on the Interface of the Report Experts, and then click Finish to access Crystal Report Designer and your report.

Fourth, is it necessary to dynamically set the data source?

Crystal Reports is connected to a database via a database driver. Each driver is written to handle specific database types or database access technologies.

Pull and push model

In order to provide developers with the most flexible data access method, the Crystal Reports database driver is designed to provide a pull-up and push model that can provide data access.

Pull-up type

In the scaffold, the driver will connect to the database and "pull" "to" "" "as needed. When using this model, the SQL commands that are connected to the database and the SQL commands executed in order to obtain data are also processed by the Crystal Reports itself, and the developer is required to write code. Use the pull model if you do not need to write any special code at runtime.

Push model

Instead, the push model requires the developer to write code to connect to the database, execute the SQL command to create a recordset or data set that matches the fields in the report, and passes the object to the report. This method allows you to share the connection into the application and filter data before Crystal Reports receives data.

Fourth, from the ADO.NET data set production report

Create a dataset object from the database

1. Create a new architecture file in the project:

a. In the Solution Explorer, right click on the project name, point to Add, and then click Add New Item.

b. In the "Category" area of ​​the Add New Item dialog, expand the folder, then select "Data". c. Select "Data Set" in the Template area.

d. Accept the default name dataset1.xsd.

This creates a new architecture file (DataSet1.xsd), which will use it to generate strong type datasets. The architecture file will be displayed in the ADO.NET Dataset Designer.

2. Specify the database location:

a. In Server Explorer, right-click "Data Connection" and select Add Connection.

b. In the Data Link Properties dialog box, click the Provider tab and select a provider (such as Microsoft Ole DB Provider for SQL Server).

c. Click the Connection tab and specify where your database is located. Enter the server and login information in the desired location.

d. Click the "OK" button.

At this point, your database and its tables and fields appear under the "Data Connection" node of the Server Explorer.

3. In the Solution Explorer, double-click DataSet1.xsd (if it is not an activity view).

DataSet1.xsd should now be displayed in the Dataset tab.

4. To establish a schema for the Data Set, drag the required tables from the Server Explorer to the Dataset1.xsd "Datase" tab.

5. Click "Save Dataset1.xsd" to save the "DataSet1.xsd" file.

6. On the Generate menu, click Generate to generate a dataset object for the project.

ADO.NET Dataset Object provides data description, from it to Crystal Report adds a table. Add a table from the ADO.NET dataset object using the "Database Expert" in Crystal Report Designer.

Please call "Database Expert" when you use the Report Experts to create a new report. Alternatively, to access the "Database Expert" from a report that has already been established using ADO.NET, right-click in Report Designer, point to "Database", and then click Add / Remove Database.

Connect the report to the ADO.NET dataset object

1. In the Database Expert, expand the Project Data folder.

2. Expand the "ADO.NET Dataset" folder.

3. Select the desired data set object.

For example, if it is used at the time of the architecture file "Dataset1.xsd" from the project "WindowsApplication1" schema file, "WindowsApplication1.DataSet1" should be selected.

4. Select the table you want to add to the report and use other data sources.

5. Dynamically change the code of the data source

DIM DSDataSet As New Dataset ()

Dim orpt as new rptclient () 'established report RPTCLIENT

Please read the reader to fill the data set on your own DSDataSet

'Use the Report Engine Object Model to pass the data set to the report

ORPT.SETDATASOURCE (DSDataSet.tables (0))

'Bind the report object with data to the Windows Form Viewer, RPTVEW (CrystalReportViewer Control)

RPtVew.Reportsource = ORPT

Note that the FillDataSet method can connect to the specified database, extract the data, and disconnect the database connection. If you want to add multiple tables in the database to the report, use the SQL JOIN statement to connect these tables together; then specify a result table in the FillDataSet method

6. Creating a master from a report

In the report, there are many reports that the primary slave table structure, such as orders and order items, the order is a record in a table, and the entry is a plurality of records in another table, and the two tables are associated with one field. This report can be implemented using its packet function, 1. Creating a new project

2. Add a CrystalReportViewer control to Form1

3. Connect to the Northwind database connected to SQL Server 2000 in the Service 噐 Explorer

4. Add a dataset DataSet1 to add the Orders and Order Details in the Server Explorer to the data set.

5. Add a crystal statement, use the report expert, select "ADO.NET Dataset" in the project data, insert table Order Details, "Link" is the link to the associated field, in the Field, select The fields of the primary table and the schedule, the selection group in the group is based on the Orders Table ORDERSID field, the total, chart, and select (screens), the style (which can be set), can be set. After setting, click Finish.

6. Adjust the position, width of the field that needs to be displayed in the report designer.

7. Add code in the window.

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.LOAD

Dim ORPT AS New CrystalReport1 ()

DIM DSDataSet As New Dataset1 ()

Dim cn as new data.sqlclient.sqlconnection (data source = pmserver; initial catalog = northwind; user ID = sa; password = sa)

Cn.open ()

Dim Daorders as new data.sqlclient.sqldataadapter (Select * from Orders, CN)

Daorders.Fill (DSDataSet, Orders)

Dim Dadetails as new data.sqlclient.sqldataadapter (Select * from [Order Details], CN)

Dadetails.Fill (DSDataSet, Order Details)

'Use the Report Engine Object Model to pass the data set to the report

ORPT.SetDataSource (DSDataSet)

CrystalReportViewer1.Reportsource = ORPT

End Sub

8, run the program

7. Use the program to change the text of the text in the report.

code show as below:

DIM GetTextObject As TextObject

'Get the ReportObject by name, convert it to TextObject, and return this object.

GetTextObject = ORPT.ReportDefinition.reportObjects.Item (Text13)

GetTextObject.text = xxxx system

Summary: The crystal statement has a very powerful function, and can also perform files such as Word, Excel, RTF, which can also generate complex, beautiful charts, are weapons developed by Web and Windows reports.

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

New Post(0)