. NET Environment Crystal Report use summary lihonggen0 (original)

Source: Internet
Author: User
Tags join object model one table

Crystal Report. NET Environment Crystal Report use summary lihonggen0 (original)

Crystal Report is an excellent report development tool, I in the development of general management system, all reports are using Crystal Report, its simple, easy-to-use and powerful function to make the author doubly like, now the Crystal Report use notes presented to everyone.

First, in the use of the Crystal Report, please register, or 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 the Crystal in your application. The ReportSource property is used to set which report to view. After this property is set, the report is displayed in the viewer. The report source can be a reportdocument, a path to a report file, or a strongly typed report.

1. Open the Toolbox and drag a crystalreportviewer onto the form, which we name as Rptvew.

2. Drag-and-drop to resize the Windows forms viewer to the size you want and move it to the desired location.

3. When you run the application, the report is displayed in the viewer.

Third, create a new report

1. Point to Add, and click Add New Item.

2. In the Add New Item dialog box, select the Crystal report from the Templates area, name Rptclient, and click Open.

3. In the Crystal database, select one of the following options:

· Use report Experts-guide you through the process of creating a report and add your selections to Crystal reports Designer.

· As a blank statement-open Crystal report Designer.

· From an existing report-Creates a new report that is the same as another report design that you specify.

Note The Crystal Report Library contains a number of experts who can guide you through the creation of several specific types of reports. You may want to use an expert to create the initial report to determine which report construction method is appropriate for your needs.

4. Click "OK" button.

If you choose to use report experts, the Report Expert dialog box appears with Data Explorer. Select the data you want for each folder, complete the actions on the Report Specialist tab interface, and then click Finish to access Crystal report Designer and your reports

Do you need to dynamically set up a data source?

Crystal Reports connects to the database through a database driver. Each driver is written to handle a specific database type or database access technology.

Pull and push model
To provide the most flexible data access methods to developers, the Crystal Reports database driver is designed to provide both a pull model and a push model for data access.

Pull model

In the pull model, the driver connects to the database and pulls the data in as needed. When using this model, the connection to the database and the SQL commands executed to get the data are handled by the Crystal Reports itself, without the need for the developer to write code. If you do not need to write any special code at run time, use the pull model.

Push model

Instead, the push model requires developers to write code to connect to the database, execute SQL commands to create a recordset 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 into your application and filter the data before Crystal Reports receives the data.

Iv. production of reports from Ado.net data sets

To create a DataSet object from a database

1. Create a new schema file in your project:

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

B. In the Add New Item dialog box, in the Categories area, expand the folder, and then select data.

C. In the Templates area, select Data set.

D. Accept the default name DataSet1.xsd.

This creates a new schema file (dataset1.xsd) that will be used later to generate a strongly typed DataSet. The schema file is displayed in the Ado.net DataSet Designer.

2. Specify the database location:

A. In Server Explorer, right-click Data Connections and select Add Connection.

B. In the Data Link Properties dialog box, click the Provider tab, and then select a provider (for example, Microsoft OLE DB Provider for SQL Server).

C. Click the Connection tab, and then specify the location of your database. Enter the server and login information at the desired location.

D. Click the OK button.

At this point, your database and its tables and fields appear under the Data Connections node in Server Explorer.

3. In Solution Explorer, double-click DataSet1.xsd (if it is not already active).

DataSet1.xsd should now appear in the DataSet tab.

4. To establish a schema for the dataset, drag the table you want from Server Explorer onto the DataSet1.xsd tab of the data set.

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

6. On the Build menu, click Build to generate the DataSet object for the project.

The Ado.net DataSet object provides a description of the data from which it can add tables to the Crystal. Add a table from the Ado.net DataSet object using the database expert in the Crystal-Designer.

Call database Expert When you create a new report by using the report expert. Or, to access the database expert from a report that you have already built with Ado.net, right-click in reports Designer, point to Database, and then click Add/Remove Database.

To connect a report to a Ado.net DataSet object

1. In database experts, expand the Project Data folder.

2. Expand the Ado.net Data set folder.

3. Select the DataSet object you want.

For example, if you were using a DataSet object that was generated from the schema file "DataSet1.xsd" of the Project "WindowsApplication1," You should select "Windowsapplication1.dataset1".

4. Select the tables you want to add to the report, as with other data sources.

Dynamic changes to data source code

Dim Dsdataset as New DataSet ()

Dim orpt as New rptclient () ' Established report rptclient

Readers are asked to fill their own dataset Dsdataset

' Use the report Engine object model to pass the populated dataset to the report

Orpt.setdatasource (dsdataset.tables (0))

' Bind a report object with data to the Windows Forms Viewer, Rptvew (Crystalreportviewer control)

Rptvew.reportsource = Orpt

Note the FillDataSet method can connect to the specified database, extract the data, and then disconnect the database. If you want to add more than one table from the database to the report, use the SQL join statement to join the tables together; then specify a result table in the FillDataSet method

Vi. Creating Master-Slave reports

In the report, there are many reports are master-slave table structure, such as order and order product details, order is a table in a record, and the ledger transactions are a number of records in another table, two tables through a field association, this report can use its grouping functions to achieve,

1. A new project

2. Add a Crystalreportviewer control to the FORM1

3. Connect to the Northwind database on SQL SERVER 2000 in the Service Compiler resource Manager

4. Add a DataSet Dataset1 to join orders and order details in the Server Explorer to the data set.

5. Add a crystal Report, use the report expert, select "ADO" in the project data. NET DataSet, insert table orders and order Details, link is the link to the associated field, in the field, select the field of the main table and the BOM that you want to display, and select groups by the Orders table Ordersid fields, totals, charts, selections (can be filtered), Style (You can set the report title) to set it yourself. When you are finished setting, click Finish.

6. Adjust the position, width, and so on of the fields you want to display in Report Designer.

7. Add code to the window.

Private Sub Form1_Load (ByVal sender 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 populated dataset to the report

Orpt.setdatasource (Dsdataset)

Crystalreportviewer1.reportsource = Orpt

End Sub

8. Run the program

Change the text in the report with the program

The code is as follows:
Dim Gettextobject as Textobject

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

Gettextobject = Orpt. ReportDefinition.ReportObjects.Item ("text13")

Gettextobject.text = "xxxx System"

Summary: Crystal Report has a very powerful function, you can also export word, EXCEL, RTF, and other files, but also generate complex, beautiful charts, is a tool for Web and Windows Report development.

(This article is part of the information from MSDN)

Author: Lee Honggen

E-mail:lihonggen0@163.com



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.

Tags Index: