将 DataTable 加载到 ReportViewer

Loading DataTable Into ReportViewer

我有一个从 sql 适配器填充的数据表。我能够让它在 datagridview 中成功显示,但是当我尝试做一个 reportviewer 时它不能正常工作。

DataTable dt = new DataTable();
dt.TableName = "SwipeReport";
da.Fill(dt);

reportViewer1.Reset();
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.ReportEmbeddedResource = "POC1.SwipeReport.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("SwipeReport", dt));
reportViewer1.RefreshReport();

我不相信我没有正确设置报告嵌入资源,因为我得到了一个 "report is not specified" 而它应该填充报告查看器 window.我是否正确执行了此操作?

希望对您有所帮助

        // create a new report from the created CrystalReport
        GeneralSupportRpt myDataReport = new GeneralSupportRpt();

        // set the data source of the report
        myDataReport.SetDataSource(dataTable);

        // set the report source of the created “crystalReportViewer”
        // component to the created report

        ReportViewer.ReportSource = myDataReport;