Summary-print the table data through the crystal report step to summarize the Crystal Report

Source: Internet
Author: User

Summary-print the table data through the crystal report step to summarize the Crystal Report

Recently, the project used Crystal Reports to print table data. Now let's take a look:

1. Install the CRforVS_13_0 Crystal Report.

2. Create a. xsd file in vs2010, create a able in it, and set the Data Type of each field.

3. create. rpt (report file), draw the table to be displayed, and then bind the database field (right-click the database field-Database Expert-my connection-expand the tree node to find the newly created DataTable) drag fields in the able table to the corresponding position.

4. in the print event on the upper page, a New able is created, the table data to be printed (for example, the data source of the DataGridView dview) is assigned to the DataTable, and a New able is created. rpt file, and set its data source 【. setDataSource (dt. rpt is assigned to the CrystalReportView control and. rpt file parameter field pass value (if. the rpt file has a parameter field )【. parameterFieldInfo ].


Issue of crystal RePort Printing

Crystal Reports can certainly be implemented. Prepare the involved tables first. Then, associate the table with the crystal report. Set the fields in the format you mentioned!

Print and preview the Crystal Report, which was made in visual studio2008 and made in C # WinForm.

The crystal report is a relatively simple thing. What you say about previewing whether there is any data is that.. net platform provides you with a preview to reflect the report style you have edited. The specific data is displayed based on the data in the database selected by the report expert. You can understand it in this way.
1. you need to separate your preview and future data, because in the crystal report, you mainly edit the format rather than the data, that is, you can specify the format in the crystal report, at the same time, you can specify the field name for each part of the data to be displayed in the future. For specific data sources, you can first put them aside. You can create it by yourself. The key here is to clarify the format and the field name of the data source.
2. If you have set the report format, you can add a new form and place a crystalreportview control in it, which is used to preview the crystal report.
Assume that the new form name is ReportView and the crystalreportview Type Control name is CryView.
The main form name is MainForm, and the print button name is btn_Print
Crystal Report Name: CryReport. rpt
Click the print button and call the ReportView form. The Code is as follows:
ReportView myRp = newReportView (ReportSqlStr );
MyRp. ShowDialog ();
The preceding parameter ReportSqlStr is the SQL statement used for data retrieval.
Write in the load event of ReportView
...
Ds = myConn. GetData ("tmpTable", tmpSql );
CryReport myrpt = new CryReport ();
Myrpt. SetDataSource (ds );
CryView. ReportSource = myrpt;
CryView. RefreshReport ();

The above tmpSql is an SQL statement passed from the previous form, and ds is a dataset
Myconn is an object. You can run the tmpsql statement to return dataset.
TmpTable is the name of a table in a custom ds instance,
Note: The field names in the tmptable must contain all the field names when editing the report. Otherwise, no data is displayed. If field A is specified at A certain position during Report Editing, if field A is not found in tmptable, the report will be blank.
The specific print and format are available in the CryView control, and no additional code is required.

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.