Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues Setting RDLC Datasource to Object

Background:

I've been tasked with converting an Access database application to ASP.Net C# MVC. This is my first MVC application.

There are 10 reports that need converting. We're using RDLC files and reportviewer. I'm using Visual Studio 2010 with all the most recent patches. We're hooking up to a SQL Server database that's been populated by the existing Access database, so the table structure is pretty much set in stone, or else we'll have to try to convert 10 years of data.

I've completed all but two of the reports. The final reports require more processing, and don't just display data from the database. The easiest way to do this would be to create a C# object and do all the processing server-side, then use RDLC to display the results.

Issue

The problem I'm having is that Visual Studio won't recognize the objects I've created as potential datasources. Every time I try to "add dataset" it brings up the "datasource configuration wizard" and only offers the SQL Server database as the possible data connection. I know there's a screen that exists that allows you to select an object as your dataset, but I never see that screen.

Here are the objects (processing functions removed for clarity):

public class TurnAroundVal
{
    // Registration Package information
    public string dataType { get; set; }

    // Calculated totals; values only set through constructor or calculation function
    public int packageCount { get; private set; }
    public int dayCount { get; set; }
    public double avgTurnAround { get; private set; }
    public int upperRange { get; private set; }
    public int lowerRange { get; private set; }
}

public class TurnAroundVals
{
    // Public Variables
    public IEnumerable<TurnAroundVal> TurnArounds { get; private set; }
    public DatePass dates { get; set; }
    public int pkgTotal { get; private set; }
    public double dayTotal { get; private set; }
    public double avgAllTurnArounds { get; private set; }
}

I also would be willing to use the IEnumerable of "TurnAroundVal" as a datasource, and just pass the dates, int, and doubles in as parameters. Either would work.

Question

Is there a setting in Visual Studio 2010 that I'm missing to allow the RDLC Designer to see the objects I created? Am I wrong in even thinking this will work with the classes I defined?

Answer

All of the suggestions given were helpful, but ultimately what got it to work for me was to create a temporary non-web project in the same solution and create the RDLC there. When I went to add a dataset, it shows "Objects" as an option. You have to add a reference to your web project so that your objects are visible, but then you can pick the one you want and use that in the RDLC. After that, you can just drag-drop the RDLC file into your web project, delete the temp project, and you're good to go. Just remember that you have to add the datasources manually in code, and they have to be named the same as you specified in the RDLC.

like image 439
War2d2 Avatar asked Jun 14 '12 17:06

War2d2


People also ask

How do I view DataSource in Rdlc?

Go to Design view, Select Smart tag. Click Choose Report Dropdown, Select RDLC report (StudentReport). Click Choose Data Source and select <New data Source>. Select Object and Give DataSource Name.

How do I add a DataSet to Rdlc?

To create a dataset for the RDLC report, click Reporting under Visual C# Items. Click Report, and then click Add. The Report Wizard opens. Enter a dataset name in Name field.To choose a data source for the dataset, click New on the right of Data source drop-down combo box.


2 Answers

  1. Make sure the classes are in the same namespace as the application.
  2. Try building the application before you create the report
  3. Start the report wizard. Under DataSouce select the name of your web application.
  4. Under Available Datasets you should see what Visual Studio interprets to be your "Select Method". If all is well, this should be TurnArounds.

You may need to put the class file in the App_Data or App_Code folder, but I am not certain.

This might also help.

http://msdn.microsoft.com/en-us/library/ms251692%28v=vs.100%29.aspx

like image 152
Marnee KG7SIO Avatar answered Oct 16 '22 15:10

Marnee KG7SIO


Set your objects under the same namespace but on a different project which you then reference on your UI project.

Also try implementing INotifyPropertyChanged.

like image 22
raphael Avatar answered Oct 16 '22 15:10

raphael