ReportViewer with multiple dataset and report parameters

This code is useful in windows application
This code will give you following ideas
1. How to embed rdlc file in report viewer.
2. How to add multiple datasets for report.
3. How to assign values to report parameters.

Not tested for web application.



//Set the report processing mode
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
//Assign report file i.e. rdlc
this.reportViewer1.LocalReport.ReportEmbeddedResource = "GI.ServiceManager.ServiceReport.rdlc";

//Add datasets
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("ProcessData", Program.CurrentServiceInstrument.Data.tblServiceReportProcessData));
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("AccessoryData", Program.CurrentServiceInstrument.Data.tblServiceReportAccessoryData));
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("Summary", Program.CurrentServiceInstrument.Data.tblServiceReportSummary));

//Create the report parameters and assign values to it
ReportParameter[] rParam = new ReportParameter[2];
rParam[0] = new ReportParameter("rpUnitType", Convert.ToString(Program.CurrentServiceInstrument.Data.tblServiceReportSummary.Rows[0]["UnitType"]));
rParam[1] = new ReportParameter("rpSerialNumber", Convert.ToString(Program.CurrentServiceInstrument.Data.tblServiceReportSummary.Rows[0]["SerialNumber"]));

//Set report parameters
this.reportViewer1.LocalReport.SetParameters(rParam);

//Refresh report to render it
this.reportViewer1.RefreshReport();


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: