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 crystal report registration code: AAP5GKS0000GDE100DS 2, using CrystalReportViewer Preview CrystalReportViewer control Allows view Crystal Report in the 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 a new report 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 - guidance you 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 Report Experts tab, and then click "Finish" to access the Crystal Report Designer and your report. Do you need 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. The pulling and push model In order to provide developers with the most flexible data access methods, the Crystal Reports database driver is designed to provide a pull-up and push model of data access simultaneously. The pull-up type is in the pull model, 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. In contrast, the push model requires developers 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 dataset, create a data set object from the database 1. Create a architecture file in the project: a. In the Solution Explorer, right-click the project name, point to "Add", and then click " Add new items.
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 the 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 position. 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 changed the data source code DIM DSDATASET AS New DataSet () DIM ORPT AS New RPTCLIENT () The established report RPTClient Please populate the data set DSDataSet 'Use the Report Engine Object Model to pass the data set, pass Give report ORPT.SetDataSource (DSDataSet.Tables (0)) 'Binds report objects with data to the Windows Form Viewer, RPtVew (CrystalReportViewer Control) RPTVEW.REPORTSOURCE = ORPT Note that FillDataSet method can connect to the specified database, Extract 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 of a result in the FillDataSet method, create a master from the report, there are many reports. The main slave structure, such as orders and orders, 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, which can be packetized Function, 1. New project 2. Add a CrystalReportViewer control to Form1 3. Connect to the Northwind database on SQL Server 2000 in the Service 噐 Explorer 4. Add a dataset DataSet1 to bring the server resource manager Orders and Order Details are added 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 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 data set, passed to report oRpt.SetDataSource (dsdataSet) CrystalReportViewer1.ReportSource = oRpt End Sub8, seven run the program, to change the report text text program code is as follows: Dim GetTextObject as TextObject 'acquired by the ReportObject name, convert it to TextObject, and returns the object .