How to create report (RDLC) without database?

后端 未结 5 2011
梦毁少年i
梦毁少年i 2020-12-29 05:02

Problem

When you create a report (RDLC) the datasource seems to be only this or that database. Is there any way to convince VS to establish a link to memory data s

5条回答
  •  星月不相逢
    2020-12-29 05:42

    Return a list of your business objects and add it as the data source:

    ReportViewer.LocalReport.DataSources.Add(new ReportDataSource("Report", new List { new ReportDto(businessObj) }));
    

    ReportDto is a wrapper for your business object where all formatting, concatenations and other report related modifications are done. It emits only the properties you need for the report.

    Then go to add data set and pick the ReportDto's namespace as the data source and pick ReportDto as the dataset. Now all the properties you have included in ReportDto will be available in the designer.

提交回复
热议问题