Rdlc报告未加载

本文关键字:加载 报告 Rdlc | 更新日期: 2023-09-27 18:06:43

我在Win Form应用程序中有一个通用的报表查看器

我正在从EF 5.0的SP中获得数据源;我有一个数据集在xml文件。包含存储过程中的属性的。

我的代码示例是
private void btnNewStaff_Click(object sender, EventArgs e)
{
        SaleManager aManager = new SaleManager();
        var reportForm = new CommonReportViewer(); 
        reportForm.commonRptViewer.LocalReport.ReportPath = "RptTransactionDetails.rdlc";
        var data = aManager.GetTransactionDetails(-9223372036854775808);
        var reportDataSource = new ReportDataSource("TransactionDetails", data);
        reportForm.ShowReport(new[] { reportDataSource });
    }

其中-9223372036854775808是事务ID(稍后会动态),数据源中的TransactionDetails是RDLC中Dataset的名称。

从ShowReport中,它将进入公共报表表单,也就是

internal void ShowReport(IEnumerable<ReportDataSource> dataSources)
{
    foreach (var dataSource in dataSources)
        commonRptViewer.LocalReport.DataSources.Add(dataSource);
    commonRptViewer.LocalReport.Refresh();
    commonRptViewer.Refresh();
}

但是没有报表加载,也没有报表,不知道问题出在哪里…

Rdlc报告未加载

您的报告路径不是实际路径。您应该将报告定义为嵌入的资源,或者定义完整的报告路径

要使用嵌入报表,使用如下命令:

reportForm.commonRptViewer.LocalReport.ReportEmbeddedResource = "RptTransactionDetails.rdlc";

要使用报告路径,计算路径(像这样):

 string appPath = Application.StartupPath;
 reportForm.commonRptViewer.LocalReport.ReportPath = Path.Combine(appPath, Reports'RptTransactionDetails.rdlc");