且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VB.Net:如何在报表 (.rdlc) 中使用对象数据源

更新时间:2023-02-24 12:56:08

从您的描述和随附的代码来看,ReportData 类中没有任何属性.如果我认为正确,该类应该生成要在报告中显示的 IEnumerable.

From your description and accompanying code, there are no properties in the ReportData class. If I reckon well, that class is supposed to be generating the IEnumerable you want to display on the report.

如果是这种情况,您必须在向导中选择 Employee 类作为数据源.这将允许您在报告中显示数据.

If that's the case, you'll have to select the Employee class as the DataSource in the wizard. This will allow you to display the data on your report.

我将处理一个快速项目,稍后将其添加到此答案中.

I'll work on a quick project and add it to this answer in a moment.


编辑 1

Visual Studio 2008

  1. 设计视图中打开报告.
  2. 从菜单栏中选择Data > Show Data Sources
  3. 点击数据源"窗口中的添加新数据源.
  4. 选择对象并点击下一步.
  5. 浏览解决方案树并选择要绑定到的类.
    在您的情况下,您绑定到 Employee 类.
  6. 点击下一步,然后完成.
  1. Open the report in Design View.
  2. Select from the menu bar Data > Show Data Sources
  3. Click Add New Data Source on the Data Sources window.
  4. Select Object and click Next.
  5. Browse the solution tree and select the class you want to bind to.
    In your case, you bind to the Employee class.
  6. Click Next and then Finish.


Visual Studio 2010

  1. 设计视图中打开报告.
  2. 从菜单栏中选择View > Report Data
  3. 在数据源"窗口中单击 New > Dataset....
  4. 输入数据集的名称(例如员工)
  5. 创建新数据源或选择现有数据源.

  1. Open the report in Design View.
  2. Select from the menu bar View > Report Data
  3. Click New > Dataset... on the Data Sources window.
  4. Enter a name for the dataset (e.g. Employee)
  5. Create a New Data source or select an existing data source.

创建新数据源

  • 选择对象并点击下一步.
  • 浏览解决方案树并选择要绑定到的类.
  • 点击完成.


将类绑定到报表后,继续像往常一样设计报表.


After binding a class to the report, go ahead and design your report as usual.

编辑 2

我为您上传了一个示例项目.这是 链接.
如果您需要进一步说明,请通知我,以便我为您提供有关如何复制项目的分步程序.

I uploaded a sample project for you. Here's the link.
If you need further clarification, please notify me so I give you a step by step procedure on how to replicate the project.