C # Use of the report control reportviewer

Source: Internet
Author: User

C # Use of the report control reportviewer

Start vs2005 to create a form project named testproj

Select "Add new data source" in the form on the left or click "Add new data source" on the menu ":

Select the dialog form and select "Database" to go to "Next ":

This data source uses the northwind database provided by sqlserver2000 as an example. Therefore, select sqlserver as the driver in the database. The specific operation depends on the database used.

(If the connection is Oracle, we recommend that you use the ODP for. net address provided by Oracle :).

After selecting the data source, specify the database file and perform a test. If the connection fails, check your software settings.

Next, go to the tables and views in the warehouse picking file, open the table, select employees, and click Finish.

In the data source window, fields in the selected table and table are displayed for use.

You can also view the newly added data file in the resource manager.

2. Report Browser

In the new form, add the report browser control:

This report browser control integrates the report view and print preview functions, which can be directly output to a printer or to an Excel file or PDF file. for customers who like to view an Excel table, this report control is very good. For more information about the report source and the background information, see related websites.

3. Create a report file

After the report browser control is selected, a small triangle appears in the upper right corner of the control. After you click it, a menu appears, select "design new report" or add a new report file in Solution Explorer:

Double-click "table" in "report items" to generate a table in the blank table. We can add data items in the table.

This report is designed in a way similar to the report design environment in VB before Ms. In the report designer, I divide a report into five parts: report title area, column title area, data display area, total area, and footer. If the design form of the report is displayed as the header and footer, the form of the report will be clearer:

Select the header and footer:

Display result:

Now, design the report:

Put a text box in the "Header" area, change the content to "Test Report", center, and zoom in and bold:

Select an appropriate column from the data source window and drag it to the "details" table in the report. The data is automatically filled in:

Save the designed report, return to the report browsing window, and select the designed report for the report Browser:

After the report file is selected, the menu is also changed:

Specify a data source for the report file and select the Data source:

OK. Save the file and run the test file.

4. Preview

Preview The generated report as follows:

Is it easy? We can also beautify this simple report. Of course, after I add some beautification functions, the effect may be worse, but this is only for demonstration purposes.

Add a table to the data.

In the report designer, select the area where you want to add a table box.

Select the border tool in the toolbar.

Select "all borders" as needed ".

It looks a little darker than the original Gray Line and can be seen during preview.

Add printing time display

Add a text box that displays the printing time, right-click it, and select attributes:

In "file box properties", select the expression generated after "value:

Select a time in the expression:

Do not forget that there must be a "=" before the expression. If not, manually add one. In order to better meet our habits, we can add a description above, such as the printing time. The expression should be slightly changed: it must start with "=", followed by "printing time: and connect the generated now function with "&" to get what we want.

Add serial numbers for rows

For demonstration, I added the sequence number column to the last column of the table.

Add a new column:

Enter related values in the column where the serial number is displayed:

The expression is followed by nothing, not null. Do not make a mistake.

Three functions have been completed. Preview:

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.