【问题标题】:Rdlc Report is not loadingRdlc 报告未加载
【发布时间】:2016-09-17 05:15:32
【问题描述】:

我在 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 中数据集的名称。

从 ShowReport 转到通用报告表单

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

    commonRptViewer.LocalReport.Refresh();
    commonRptViewer.Refresh();
}

但是没有报告表单加载也没有报告,无法弄清楚问题出在哪里..

【问题讨论】:

  • GetTransactionDetails 函数的返回类型是什么?

标签: c# sql sql-server rdlc


【解决方案1】:

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

要使用嵌入式报告,请使用:

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

要使用报告路径,请计算路径(类似这样):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 1970-01-01
    • 2019-01-08
    • 2017-02-24
    相关资源
    最近更新 更多