This article is mainly for you to introduce in detail the C # use ReportViewer generated reports related code, with a certain reference value, interested in small partners can refer to
This article is mainly using Microsoft's own control ReportViewer for the report design of small examples, the specific content as follows
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:
<summary>///Setup Report///</summary> private void Setreport () {//First step: Clear previous data This.rptView.LocalRepor T.datasources.clear (); Step Two: Specify the report path This.rptView.LocalReport.ReportPath = "REPORT2.RDLC"; Step three: Construct a new datatable datatable dt = new DataTable ("DataTable1"); Dt. Columns.Add ("Name"); Dt. Columns.Add ("Score"); Dt. Columns.Add ("Id"); Dt. Rows.Add (new object[] {"Language", "Y0001"}); Dt. Rows.Add (new object[] {"Math", "S0001"}); Dt. Rows.Add (new object[] {"English", "E0001"}); The name cannot be written incorrectly, and the dataset name in the report is consistent reportdatasource Rdsitem = new ReportDataSource ("DataSet1", DT); There can be more than one data source This.rptView.LocalReport.DataSources.Add (Rdsitem); Fourth step: Construction parameters list<reportparameter> Lstparameter = new list<reportparameter> () {New ReportParameter ("Title") , This.txtTitle.Text), New ReportParameter ("Id", This.txtId.Text), New ReportParameter ("Name", This.txtName.Text), n EW ReportParameter ("Age", This.txtAge.Text), New ReportParameter ("Sex", This.txtSex.text), New ReportParameter ("Salary", This.txtSalary.Text), New ReportParameter ("Depart", This.txtDepart.Text)}; This.rptView.LocalReport.SetParameters (Lstparameter); This.rptView.ZoomMode = zoommode.percent; this.rptView.ZoomPercent = 100; Fifth step: Refresh the report This.rptView.RefreshReport (); }