how to set Datatable as datasource in ReportViewer

前端 未结 3 1349
广开言路
广开言路 2020-12-17 05:45

I was searching in the last question about Datatable as datasource in ReportViewer and i found this as solution

DataTa         


        
3条回答
  •  囚心锁ツ
    2020-12-17 06:41

    It seems you have forgotten to set the report source for your report viewer control. You can set the report source using either of this options:

    • LocalReport.ReportEmbeddedResource : The name of the report-embedded resource.
    • LocalReport.ReportPath : The file system path of the local report.
    • LocalReport.LoadReportDefinition(Stream): Loads a report definition for processing using a Stream.
    • LocalReport.LoadReportDefinition(TextReader) Loads a report definition from the local file system using a TextReader.

    For example, I suppose you have added a report to your project, so you can show it in the report viewer this way:

    var reportDataSource1 = new ReportDataSource("NameOfReportDataSet", YourDataTable);
    this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
    this.reportViewer1.LocalReport.ReportEmbeddedResource = "Namespace.ReportName.rdlc";
    this.reportViewer1.RefreshReport();
    

    Also you can simply set the report of the report viewer using designer. Put a report viewer on your form and click on top-right arrow to open the smart tag window of report viewer, then choose a report from combo box.

提交回复
热议问题