问题
I got myself a BiningList
Of student (Entity Framework created class).
I just want to feed my RDLC
report from that instead of using DataSet
or stored procedures.
This class contains multiple properties like :
string Name;
string FamilyName;
string Mid;
DateTime Birth;
...
Any one can help me with that?
回答1:
Option 1 - Using designer
- Open 'Add New Item' window by pressing Ctrl +Shift +A or from 'Project' menu choose 'Add New Item ...'.
- From the window, choose Report Wizard
- In 'Report Wizard' window, click 'New ...' button in front of 'Data source' combo box.
- Complete 'Data Source Configuration Wizard'. In first page choose Object and click Next button, then in the next page, from tree, find your business object and check the checkbox near it and click Finish button to close the data source configuration wizard.
- Complete the 'Report Wizard'. The business object will be selected as data source of the report, so follow the wizard by click on Next and then in 'Arrange Fields' page, add some files from 'Available fields' to 'Σ Values' list by drag and drop. the in next pages 'Choose the layout' and 'Choose a style' and click Finish.
- Open a
Form
and from the Toolbox put aReport Viewer
control on the form. - Open 'Report Viewer Tasks' by click on and then 'Choose Report' from combo box. Then a
BindingSource
will be added to the form. Double click on
Form
to handleLoad
event and add this code to the event handler:var data = db.Students.ToList(); this.studentBindingSource.DataSource = data; this.reportViewer1.RefreshReport();
Option 2 - Using Code
Put a ReportViewer
control on a form and handle Load
event of form and write this code:
var data = db.Students.ToList();
var reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
reportDataSource1.Name = "DataSet1";
reportDataSource1.Value = data;
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportSample.Report1.rdlc";
this.reportViewer1.RefreshReport();
reportDataSource1.Name
should be name of DataSet
in your report definition. To see it, open the report and in Report Data window, under Datasets node see the dataset name.
If you set report using ReportEmbeddedResource
, then the property should be name of the report in embedded resources. If it starts with default name space of project and continue with folder names if your report is in a folder in solution explorer and at last the name of report.
来源:https://stackoverflow.com/questions/38692746/feed-rdlc-local-report-report-from-list-entity-framework