Windows report add to datasource list
I have a little problem :) I have created entity which i want to f开发者_如何学Cill and display in windows report in VS 2008.
My entity code
namespace MvcApplication3.entities
{
public class invoiceRow
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname{get;set;}
public decimal Income { get; set; }
}
}
What I want to do, is get this entity displayed in datasource vindow for report, so i can pick data source(with the entity and add it to the report). I know how to bind it but not how to get report to detect this entity.
I have found if i create class : with code as follows,
public List<invoiceRow> rows()
{
List<invoiceRow> list = new List<invoiceRow>();
return (list);
}
the report will detect the entity. How ever i do not understand why? does it have to be as it has to have data source, to display entity in report data sources?
There seems to be nothing wrong with your entity class. To me it works as a data source. Have you searched hard enough because I think the Data Source Configuration Wizard sorts the classes by their namespace. Here is my code:
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.LoadReportDefinition(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyProject.Report1.rdlc"));
reportViewer1.LocalReport.DataSources.Clear();
var dataSourcesNames = (ReadOnlyCollection<string>) reportViewer1.LocalReport.GetDataSourceNames();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(dataSourcesNames[0], objectCollection));//objectCollection is a List<MyObject>
reportViewer1.RefreshReport();
And yes the object data source always has to be a collection. If you think it is kinda like database table (which always has multiple rows in some phase).
精彩评论