C # using ReportViewer to generate reports

Source: Internet
Author: User

This article is a small example of report design using Microsoft's own control ReportViewer

Knowledge points involved:

    • ReportViewer: Located in the Microsoft.Reporting.WinForms namespace, used primarily for report display
    • Report: Reports, files ending in rdlc, visual design report templates.
    • Report data: Built-in fields, parameters, images, datasets (this report mainly uses parameters, and datasets)
    • ReportParameter: Instantiating a new report parameter with a name and value
    • ReportDataSource: The data source of a report is associated with a DataTable object

As follows:

The relevant code is as follows:

1 /// <summary>2         ///set up a report3         /// </summary>4         Private voidSetreport ()5         {6             //First step: Clear the previous data7              This. RptView.LocalReport.DataSources.Clear ();8             //Step Two: Specify the report path9              This. RptView.LocalReport.ReportPath ="REPORT2.RDLC";Ten             //Step Three: Construct a new DataTable OneDataTable dt =NewDataTable ("DataTable1"); ADt. Columns.Add ("Name"); -Dt. Columns.Add ("score"); -Dt. Columns.Add ("Id"); theDt. Rows.Add (New Object[] {"language", the,"Y0001" }); -Dt. Rows.Add (New Object[] {"Mathematics", the,"S0001" }); -Dt. Rows.Add (New Object[] {"English", the,"E0001" }); -             //The name cannot be written incorrectly, and the dataset name in the report is the same +ReportDataSource Rdsitem =NewReportDataSource ("DataSet1", DT); -             //There can be multiple data sources here +              This. RPTVIEW.LOCALREPORT.DATASOURCES.ADD (Rdsitem); A             //Fourth step: Construct Parameters atList<reportparameter> Lstparameter =NewList<reportparameter>() { -                 NewReportParameter ("Title", This. Txttitle.text), -                 NewReportParameter ("Id", This. Txtid.text), -                 NewReportParameter ("Name", This. txtName.Text), -                 NewReportParameter (" Age", This. Txtage.text), -                 NewReportParameter ("Sex", This. Txtsex.text), in                 NewReportParameter ("Salary", This. Txtsalary.text), -                 NewReportParameter ("Depart", This. Txtdepart.text) to             }; +              This. RptView.LocalReport.SetParameters (lstparameter); -              This. Rptview.zoommode =zoommode.percent; the              This. rptview.zoompercent = -; *             //Fifth Step: Refresh the report $              This. Rptview.refreshreport ();Panax Notoginseng}
View Code

SOURCE Download Link

C # using ReportViewer to generate reports

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.