【问题标题】:wpf reportviewer EFwpf 报表查看器 EF
【发布时间】:2012-11-09 00:19:06
【问题描述】:

整天寻找使用实体框架的 RDLC 报告的 WPF 应用程序的教程,但没有运气。 找到了一个很好的教程,只有 SQLCLient link 奇怪的是,在我的 WPF 应用程序中,我的 ReportViewer 没有智能标记 photo

问:如何使用 EF 将数据填充到 rdlc 报告中?

【问题讨论】:

  • 我想知道这一点以及我们越来越多地过渡到 EF。

标签: wpf entity-framework reportviewer rdlc


【解决方案1】:

添加对 Microsoft.ReportViewer.WinForms.dll 版本 10.0.0.0 的引用

标记代码:

<Window ...
    xmlns:RV="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"Title="WPF_RDLC" >
<Grid>
    <WindowsFormsHost  Name="wiFormsHost1">
        <RV:ReportViewer x:Name="Report1">
        </RV:ReportViewer>
    </WindowsFormsHost>
</Grid>

代码隐藏

private void DisplayReport()
    {
        WPF_Entities db = new WPF_Entities();
        try
        {
            var qry = db.People.AsEnumerable(); // 
            Report1.ProcessingMode = ProcessingMode.Local;
            Report1.LocalReport.ReportEmbeddedResource = "WPFApp1.Reports.People.rdlc"; // .Reports if the report isin the Reports folder not in the root
            ReportDataSource dataSource = new ReportDataSource("DS_people", qry);
            Report1.LocalReport.DataSources.Clear();
            Report1.LocalReport.DataSources.Add(dataSource);

            Report1.RefreshReport();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

添加一个 RDLC 报告(在 Reports 文件夹中),其中包含一个数据源文件 (.xsd),该文件包含实体 People 和名称为“People.rdlc”的数据集名称为 DS_people

【讨论】:

    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    • 2011-09-30
    • 2016-09-18
    • 1970-01-01
    相关资源
    最近更新 更多