Microsoft Reporter with Business Object

Published on Tuesday, March 1, 2011

Microsoft Reporter does not only support database, but also a business object. You can create class as your data source of report RDLC file.

Here is a sample from MSDN:

using System;
using System.Collections.Generic;

public class Product {
    private string m_name;
    private int m_price;

    public Product(string name, int price) {
        m_name = name;
        m_price = price;
    }

    public string Name {
        get {
            return m_name;
        }
    }

    public int Price {
        get {
            return m_price;
        }
    }
}


public class Merchant {
    private List<Product> m_products;

    public Merchant() {
        m_products = new List<Product>();
        m_products.Add(new Product("Pen", 25));
        m_products.Add(new Product("Pencil", 30));
        m_products.Add(new Product("Notebook", 15));
    }

    public List<Product> GetProducts() {
        return m_products;
    }
}

Add a report to the project using the Report Wizard

  1.  From the Project menu, select Add New Item.
    
  2.  In the Add New Item dialog, select Report Wizard. Type a name for the report and click Add.
    
    This launches the Report Wizard with the Data Source Configuration Wizard.
  3.  In the Choose a Data Source Type page, select Object and click Next.
    
  4.  In the Select the Data Objects page, expand the class hierarchy under BusinessObject until you see Product in the list. Select Product and click Finish.
    
    You now return to the Report Wizard. Notice that the new data source object is added to your project in Solution Explorer.
  5.  In the Dataset Properties page, in the Data source box, verify that global is selected.
    
  6.  In the Available datasets box, verify that Product is selected.
    
  7.  Click Next.
    
  8.  In the Arrange Fields page do the following:
    
    1.        Drag Name from available fields to the Row groups box.
      
    2.        Drag Price from available fields to the Values box.
      
  9.  Click Next twice, then click Finish.
    
    This creates the .rdlc file and opens it in Report Designer. The tablix you created is now displayed in the design surface.
  10.  Save the .rdlc file.
    

from MSDN