【问题标题】:ReportViewer not showing RDLC reportReportViewer 不显示 RDLC 报告
【发布时间】:2017-10-10 05:47:00
【问题描述】:

这里 Powerfail_101 是数据库表名称,存储 Powerfail 数据。RDLC 报告在 ReportViewer.ReportViewer 上没有显示任何数据,数据为空。

private void GenerateReport(object dt) 
{
    if (this.InvokeRequired)
    {
        MyDelegate mydelegate = new MyDelegate(GenerateReport);
        this.Invoke(mydelegate, new object[] { dt });
    }
    else
    {
        DataTable table = (DataTable)dt;
        if (table.Rows.Count != 0)
        {

            table.TableName = "table";

            // Clear the rows to clear any previous data.
            DataLogger_DBDataSet.PowerFail_101.Rows.Clear();

            DataLogger_DBDataSet.Tables.Add(table);

            string exeFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            string reportPath = System.IO.Path.Combine(exeFolder, @"Report\PowrfailReport.rdlc");

            reportViewer1.LocalReport.ReportPath = reportPath;
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.ReportEmbeddedResource = reportPath;


            ReportDataSource rds = new ReportDataSource("DataSet1", DataLogger_DBDataSet.Tables["table"]);
            reportViewer1.LocalReport.DataSources.Add(rds);
            this.reportViewer1.RefreshReport();
        }
    }
}

【问题讨论】:

  • 请参考此链接如何使用 ReportViewer 以及分配您可能错过的数据源的步骤mindstick.com/Articles/1118/…
  • 我已删除版本 10 ReportViewer 并添加了版本 11 ReportViewer 的参考。但我仍然收到空白的 reportViewer,没有数据..
  • 请让我摆脱 dis
  • 为什么要设置两次报告路径,此行不是必需的。 reportViewer1.LocalReport.ReportPath = reportPath;

标签: c# winforms


【解决方案1】:

我认为你没有像我评论中的链接那样一步一步地走

示例

reportViewer1.LocalReport.DataSources.Clear(); //clear report
reportViewer1.LocalReport.ReportEmbeddedResource = reportPath; // bind reportviewer with .rdlc

Microsoft.Reporting.WinForms.ReportDataSource rds = new 
Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", DataLogger_DBDataSet.Tables["table"]); // set the datasource
reportViewer1.LocalReport.DataSources.Add(rds);
rds.Value = DataLogger_DBDataSet.Tables["table"];  //also this line may be required

reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport(); // refresh report

【讨论】:

  • 不..我做了。我点击了链接
猜你喜欢
  • 2016-04-16
  • 2021-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 2010-11-20
相关资源
最近更新 更多