Step 1. Create a new window, drag a ReportViewer control up, and set the dock for the control to fill.
Step 2. Add a report file, such as: REPORT1.RDLC, set the parameters, and the parameters set here are corresponding to the parameters in the following code.
1 //load the report file, in the Debug directory2 This. ReportViewer1.LocalReport.ReportPath ="REPORT1.RDLC";3 4 This. Reportviewer1.processingmode =processingmode.local;5 reportViewer1.LocalReport.DataSources.Clear ();6DataTable dt =NewDataTable ();7DataColumn col1 =NewDataColumn ("name", System.Type.GetType ("System.String"));8DataColumn col2 =NewDataColumn ("School Number", System.Type.GetType ("System.String"));9DataColumn col3 =NewDataColumn ("Sex", System.Type.GetType ("System.String"));TenDataColumn Col4 =NewDataColumn ("Age", System.Type.GetType ("System.Int32")); One dt. Columns.Add (col1); A dt. Columns.Add (col2); - dt. Columns.Add (col3); - dt. Columns.Add (COL4); theDataRow Row1 =dt. NewRow (); -row1["name"] ="Zhang San"; -row1["School Number"] ="2016111"; -row1["Sex"] ="male"; +row1["Age"] = -; - dt. Rows.Add (ROW1); + //static data is not added to the data source A //ReportDataSource rds1 = new ReportDataSource ("DataSet1", DT); at //ReportViewer1.LocalReport.DataSources.Add (RDS1); -ReportParameter REPORTPARAMETER_XM =NewReportParameter ("REPORTPARAMETER_XM"Dt. rows[0]["name"]. ToString ()); -ReportParameter reportparameter_xh =NewReportParameter ("Reportparameter_xh"Dt. rows[0]["School Number"]. ToString ()); -ReportParameter REPORTPARAMETER_XB =NewReportParameter ("REPORTPARAMETER_XB"Dt. rows[0]["Sex"]. ToString ()); -ReportParameter Reportparameter_nl =NewReportParameter ("Reportparameter_nl"Dt. rows[0]["Age"]. ToString ()); -ReportViewer1.LocalReport.SetParameters (Newreportparameter[] {reportparameter_xm, reportparameter_xh, REPORTPARAMETER_XB, reportparameter_nl}); inReportviewer1.refreshreport ();
C#winform Preliminary report