I recently ran in to a problem using the reporting tools where I had a custom object with no blank constructor. In order to make the reports dynamic and change the report based on some sort of id supplied I came up with the following solution.
Explanation of Process:
Object Car is pulled from the database
Fields of object car are placed in to fields of report
So by doing the following and creating an instance of the Report, binding it to the report viewer, you can have any object bound to any field on the report. I hope this helps.
Explanation of Process:
Object Car is pulled from the database
Fields of object car are placed in to fields of report
public partial class CarReport : Report { |
public CarReport() { |
} |
public CarReport(int id){ |
Car c = GetFromDB.GetCar(23); |
txtName.Value = c.Name; |
txtType.Value = c.Type; |
} |
} |
class GetFromDB { |
public Car GetCar(int id) { |
//Query Datbase and parse info |
return new Car("FastCar", "Porsche"); |
} |
} |
class Car { |
private string strName; |
private string strType; |
public Car(string Name, string Type) { |
strName = Name; |
strType = Type; |
} |
public string Name { get { return strName; } } |
public string Type { get { return strType; } } |
} |
So by doing the following and creating an instance of the Report, binding it to the report viewer, you can have any object bound to any field on the report. I hope this helps.