从列表(实体框架)提供RDLC(本地)报告报告 [英] Feed RDLC (Local) report report from List (Entity FrameWork)

查看:162
本文介绍了从列表(实体框架)提供RDLC(本地)报告报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个 BiningList 学生(实体框架创建的课程)。

I got myself a BiningList Of student (Entity Framework created class).

我只想喂我的 RDLC 报告,而不是使用 DataSet 或存储过程。

I just want to feed my RDLC report from that instead of using DataSet or stored procedures.

此类包含多个属性,如:

This class contains multiple properties like :

string Name;
string FamilyName;
string Mid;
DateTime Birth;
...

任何人都可以帮助我吗?

Any one can help me with that?

推荐答案

选项1 - 使用设计师



Option 1 - Using designer


  1. 打开'按 Ctrl + Shift + A 或从项目添加新项目选择添加新项目...

  2. 在窗口中,选择报告向导

  3. 报告向导窗口中,点击数据源组合框前面的新建... 按钮。

  4. 完成数据源配置向导'。在第一页中,选择对象,然后单击下一步按钮,然后在下一页中,从树中找到您的业务对象,并选中其旁边的复选框,然后单击完成按钮关闭数据源配置向导。

  5. 填写报告向导。业务对象将被选作报告的数据源,因此请点击 Next 向导,然后在排列字段页面中添加一些文件, strong>可用字段'拖放到Σ值列表。在下一页选择布局选择样式,然后点击完成

  6. 打开表单,从工具箱中,在表单上放置一个报表查看器控件。

  7. 点击,然后选择报告 '从组合框。然后,一个 BindingSource 将被添加到表单中。

  8. 双击表单来处理加载事件并将此代码添加到事件处理程序:

  1. Open 'Add New Item' window by pressing Ctrl +Shift +A or from 'Project' menu choose 'Add New Item ...'.
  2. From the window, choose Report Wizard
  3. In 'Report Wizard' window, click 'New ...' button in front of 'Data source' combo box.
  4. Complete 'Data Source Configuration Wizard'. In first page choose Object and click Next button, then in the next page, from tree, find your business object and check the checkbox near it and click Finish button to close the data source configuration wizard.
  5. Complete the 'Report Wizard'. The business object will be selected as data source of the report, so follow the wizard by click on Next and then in 'Arrange Fields' page, add some files from 'Available fields' to 'Σ Values' list by drag and drop. the in next pages 'Choose the layout' and 'Choose a style' and click Finish.
  6. Open a Form and from the Toolbox put a Report Viewer control on the form.
  7. Open 'Report Viewer Tasks' by click on and then 'Choose Report' from combo box. Then a BindingSource will be added to the form.
  8. Double click on Form to handle Load event and add this code to the event handler:

var data = db.Students.ToList();        
this.studentBindingSource.DataSource = data;
this.reportViewer1.RefreshReport();




选项2 - 使用代码



将一个 ReportViewer 控件放在窗体上,并处理加载表单事件并写这段代码:

Option 2 - Using Code

Put a ReportViewer control on a form and handle Load event of form and write this code:

var data = db.Students.ToList();
var reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
reportDataSource1.Name = "DataSet1"; 
reportDataSource1.Value = data;             
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportSample.Report1.rdlc";
this.reportViewer1.RefreshReport();

reportDataSource1.Name 应该是 DataSet 在您的报告定义。要查看它,请打开报表,并在报表数据窗口中的Datasets节点下查看数据集名称。

reportDataSource1.Name should be name of DataSet in your report definition. To see it, open the report and in Report Data window, under Datasets node see the dataset name.

如果您使用 ReportEmbeddedResource ,那么属性应该是嵌入资源中的报表的名称。如果它以项目的默认名称空间开始,并且如果您的报告位于解决方案资源管理器中的文件夹中,并且最后是报告名称,则继续使用文件夹名称。

If you set report using ReportEmbeddedResource, then the property should be name of the report in embedded resources. If it starts with default name space of project and continue with folder names if your report is in a folder in solution explorer and at last the name of report.

这篇关于从列表(实体框架)提供RDLC(本地)报告报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆