Microsoft Reporter with Business Object
2011-03-01
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
-
From the Project menu, select Add New Item.
-
This launches the Report Wizard with the Data Source Configuration Wizard.In the Add New Item dialog, select Report Wizard. Type a name for the report and click Add.
-
In the Choose a Data Source Type page, select Object and click Next.
-
You now return to the Report Wizard. Notice that the new data source object is added to your project in Solution Explorer.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.
-
In the Dataset Properties page, in the Data source box, verify that global is selected.
-
In the Available datasets box, verify that Product is selected.
-
Click Next.
-
In the Arrange Fields page do the following:
-
Drag Name from available fields to the Row groups box.
-
Drag Price from available fields to the Values box.
-
-
This creates the .rdlc file and opens it in Report Designer. The tablix you created is now displayed in the design surface.Click Next twice, then click Finish.
-
Save the .rdlc file.
from MSDN