VB.Net:如何使用一个对象的数据源中的报告(.rdlc)数据源、如何使用、对象、报告

2023-09-03 00:41:12 作者:伪装.

我的问题是类似this 之一,但我有一些问题的实际执行情况。

My question is similar to this one but I'm having some problems with the actual implementation.

我有在一个3层应用程序的业务层的报告(.rdlc)。

I've got a report (.rdlc) in the business layer of a 3-tier app.

我已经得到了BL( EmployeeManager ),其中有一个装getEmployees(出pression为Ex pression对象(作者Func键(员工,布尔)))作为IQueryable的(员工)方法。

I've got an object in the BL (EmployeeManager) which has a GetEmployees(Expression as Expression(Of Func(Of Employee, Boolean))) As IQueryable(Of Employee) method.

由于我没有想尝试,并通过一个lambda直接(至少直到我已经得到的东西的工作),我创建了一个 ReportData 类其中封装了装getEmployees()通话,并公开结果作为一个IEnumerable(员工)的BL - 这应该是很简单的。它甚至不此刻有参数。

As I didn't want to try and pass a lambda in directly (at least not until I've got something working), I've created a ReportData class in the BL which wraps the GetEmployees() call and exposes the results as an IEnumerable(Of Employee) - which should be very simple. It doesn't even have parameters at the moment.

好吧......所以在我的报告,我试图增加一个新的数据源。我选择了一个类型对象和位于上述 ReportData 类。向导完成并增加了一个数据源文件夹里面的项目是一些XML定义< GenericObjectDataSource> 并指着报告类。

Ok... So In my report, I've tried to add a new Data Source. I've picked a type of Object and located the ReportData class mentioned above. The wizard completes and adds a DataSources folder to the project inside which is some XML defining a <GenericObjectDataSource> and pointing at the Report class.

ReportData 也出现在数据源面板 - 它有一个&GT; 旁边,但是当我展开它,它有没有孩子。

ReportData also appears in the Data Sources pane - It has a > next to it but when I expand it, it has no children.

我不知道叫什么怎么做的是使用的数据源 - 这似乎并没有公开任何方法/成员(我还没有规定它应该叫装getEmployees()呢!),我当然不能看到的IEnumerable(员工)的任何地方。

What I don't know how to do is USE the data source - It doesn't seem to expose any methods/members (I haven't even specified that it should call GetEmployees() yet!) and I certainly can't see an IEnumerable(Of Employee) anywhere.

当我试图将一个表添加到报告,它会提示我选择一个数据集时,ReportData数据源未在数据源下拉列表显示。

When I try to add a table to the report and it prompts me to select a Dataset, the ReportData Datasource is not shown in the Data source drop-down.

我在想什么?可有人请点我朝着正确的方向?

What am I missing? Can someone please point me in the right direction?

我简单ReportData对象:

My simple ReportData object:

Namespace Reports
    Public Class ReportData

        Private Property EmployeeManager As Interfaces.IEmployeeManager

        Public Sub New()
            ''This sub is here in case it's an instantiation problem - I intend to use dependency injection when I've got this working properly.
            Me.EmployeeManager = New EmployeeManager
        End Sub

        Public Sub New(ByVal EmployeeManager As Interfaces.IEmployeeManager)
            Me.EmployeeManager = EmployeeManager
        End Sub

        Public Function GetEmployees() As IEnumerable(Of Employee)
            Return EmployeeManager.GetEmployees()
        End Function
    End Class
End Namespace

我还发现这这似乎表明我下面的正确的步骤,但属性不会出现预期

I've also found this which seems to indicate I'm following the correct steps but the properties don't appear as expected

类的公共属性,现在出现在Data Sources窗口,在那里他们可以拖放到报告中。

The public properties of the class now appear in the Data Sources window, where they can be dragged and dropped into the report.

这不会发生 - 属性不会出现

This doesn't happen - the properties never appear

修改:正如由Alex,我需要使用属性不是任何方法。请参阅下面的说明亚历克斯Esselfie的答案。这仍然没有解决我的问题,但也让我更近了一步......

EDIT: As pointed out by Alex, I need to use properties not just any methods. Please see Alex Esselfie's answer below for clarification. This still hasn't solved my problem but has got me a step closer...

推荐答案

从你的描述和相应的code,还有在 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.

如果是这样的话,你就必须选择 员工 类向导中的数据源。这将允许您显示在您的报告中的数据。

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中

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

的Visual Studio 2010

在打开报表的设计视图 从菜单栏中选择查看> 报告数据 点击> 数据集... Data Sources窗口上。 为数据集输入一个名称(如员工)

创建的新的数据源的或者选择现有的数据源。 Open the report in Design View. Select from the menu bar View > Report Data Click New > Dataset... on the Data Sources window. Enter a name for the dataset (e.g. Employee)

Create a New Data source or select an existing data source.

创建新的数据源

选择对象,然后点击的下一步的 浏览解决方案的树,并选择类(ES)你要绑定到。 点击完成的 Select Object and click Next. Browse the solution tree and select the class(es) you want to bind to. Click Finish.

后一类具有约束力的报告,继续前进,设计照常报告。

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.