views:

343

answers:

1

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

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

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.

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.

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 also appears in the Data Sources pane - It has a ">" next to it but when I expand it, it has no children.

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.

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?

Many thanks

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

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

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...

+1  A: 

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.



Edit 1

How to Bind a Class to a Report

Visual Studio 2008

  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. 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.

    Creating a New Data source

    • 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.


Edit 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.

Alex Essilfie
Thank you - do you mean that it actually has to be a property not a function? I'd appreciate the sample project but I'll test that as well...
Basiclife
Ok, changing it to a property has got me further - I can now see a child element (GetEmployees()) on the Data source in the Data sources pane - but it's still not listed when I add a table and it asks me for a data set - Do I need to do something to use a data source as a data set?
Basiclife
It is a class that you bind a report to. When a class is bound to a report, it's properties become possible fields for display on that report. Therefore you'll have to bind the report to the return value (`Employee` in this case).
Alex Essilfie
I just finished the sample project. Do you want me to upload the entire project or should I just edit my answer to display the meat of the project.
Alex Essilfie
Hi Alex, can you clarify how I would bind the report? I can't see anything in the properties pane which seems to apply...
Basiclife
Basiclife, which version of VS are you using? 2008/2010?
Alex Essilfie
VS2010 and a .Net4 project
Basiclife
Sorry about the delay. My internet connection got disconnected. I updated the answer to show how to bind a class to the report.
Alex Essilfie
Hi Alex, not a problem... If I do "Show Data Sources", I get a data sources window with a very small tree (Reports -> ReportData -> GetEmployees). There is no "New" option. Buttons I have are: Add new data source (not set). Refresh. Greyed out are: Edit Dataset with designer and configure data source with wizard. These remain greyed out no matter which node is selected. On the VS Data menu, I have Add new Data Source again but no mention of set...
Basiclife
I've uploaded a screenshot here: http://img25.imagevenue.com/img.php?image=65460_UI_122_6lo.jpg
Basiclife
After seeing your screenshot I think it's best I upload the sample project. Pardon my tardiness. I've been having a poor internet connection today.
Alex Essilfie
Basiclife, I'm sorry I made a slight mistake in the procedure for adding a data source in VS2010. Please see the updated answer for the corrected version.
Alex Essilfie
+1 Alex - Thank you so much for your help on this. You've been very helpful and I really appreciate the step-by-step above. I've now managed to get data into my report. I've still got questions but you've answered this one - I'll open some new ones up over the next day or so.
Basiclife
No problem. I had to learn MS Reports last month on my own with no assistance whatsoever so as much as possible, I try not to let anyone go through that experience. Knowledge is meant to be shared after all.
Alex Essilfie
Thanks. In case you're interested, follow-up Q is here: http://stackoverflow.com/questions/3726658/using-microsoft-reports-rdlc-in-a-3-tier-app
Basiclife