Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using .NET Class as the DataSource with SSRS RDLC

I have a MVC4 application in Visual Studio 2010 which contains plenty of classes. I'm trying to use them to pass in as the DataSource for a Report Definition Language Client (RDLC) file. But I can't access the classes from my assembly anywhere in the data source designer

According to the MSDN Walkthrough on Using a Business Object Data Source with the ReportViewer Web Server Control in Local Processing Mode, I should be able to do so in the Dataset Properties page

In the Dataset Properties page, in the Data source box, select global.

According to this Stackoverflow question on How to use an Object data source in report (.rdlc), when in Dataset Properties page, I should be able to create a new data source like this:

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.

But neither of these present as options...

When I create a new dataset, nothing shows up under Data Source:

DataSet Properties

When I click New to create a New DataSource, I just get a connection Wizard that forces me to connect to a database:

Data Source Configuration Wizard

Where can I add classes from my assembly?

As a trivial example, here's an example of an object I have built into the assembly that I would expect to show up:

Public Class Employee
    Public Property Name As String
    Public Property ID As Integer
End Class

I would eventually like to populate this information programmatically like this:

Dim lr As New LocalReport
lr.ReportPath = Server.MapPath("~\Reports\Report1.rdlc")
lr.DataSources.Add(New ReportDataSource("Data", New Employee("Kyle",27)))
like image 330
KyleMit Avatar asked Dec 29 '14 20:12

KyleMit


2 Answers

Here are a couple solutions, but I prefer the second one.

Solution 1 (okay)

As this appears to be a bug with the MVC Web Application project type itself, you can add the report to a different project type (like Class Library). As described in the post Visual Studio 2010 Report Viewer - Object Datasource, just create a separate library for the project and add the rdlc file there. The data source configuration wizard should now look like this:

data source configuration wizard

Solution 2 (better)

As figured out in Can't see or add Website Data Sources in RDLC report in ASP.NET MVC, you can just add an aspx page anywhere to the MVC project to trick Visual Studio into pulling in the right design time libraries.

Just do the following:

  • Close all windows
  • Clean & Rebuild Solution
  • Add WebForm1.aspx to the Project
  • Open up the RDLC file and choose a DataSource from the dropdown:

    DataSource Dropdown

like image 148
KyleMit Avatar answered Oct 14 '22 18:10

KyleMit


Solution: Delete all contents and folder from Bin and Obj folder from your project directory and rebuild your solution.

I faced the same problem in Visual Studio 2015 with ASP.NET MVC5 when adding Data Sources of RDLC Report. Everything was working well when adding Data Sources in my current project. But suddenly in new reports I wasn't finding my project desired/updated/new classes as Data Sources in RDLC report data.

When I deleted all the contents from Bin and Obj folders of the current project, everything started working again

like image 37
Muhammad Ashikuzzaman Avatar answered Oct 14 '22 16:10

Muhammad Ashikuzzaman