2012-03-26 47 views
1

整天看了一篇關於WPF應用程序的教程,其中使用實體框架的RDLC報告沒有運氣。 發現只有SQLCLIENT link 一個很好的教程奇怪的是,在我的WPF應用程序我的ReportViewer不具有智能標記photowpf reportviewer EF

問:我如何填充數據使用EF一個RDLC報告?

+0

我想知道這一點以及我們越來越多地轉向EF。 – 2012-03-26 19:54:32

回答

0

添加參考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文件夾中)與包含實體People和具有DataSet名稱的名稱「People.rdlc」的DataSource文件(.xsd)DS_people