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