Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feed RDLC (Local) report report from List (Entity FrameWork)

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?

like image 926
alireza amini Avatar asked Mar 12 '23 13:03

alireza amini


1 Answers

Option 1 - Using designer

  1. Open 'Add New Item' window by pressing Ctrl +Shift +A or from 'Project' menu choose 'Add New Item ...'.
  2. From the window, choose Report Wizard
  3. In 'Report Wizard' window, click 'New ...' button in front of 'Data source' combo box.
  4. 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.
  5. 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.
  6. Open a Form and from the Toolbox put a Report Viewer control on the form.
  7. Open 'Report Viewer Tasks' by click on Smart tag icon and then 'Choose Report' from combo box. Then a BindingSource will be added to the form.
  8. Double click on Form to handle Load 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.

like image 108
Reza Aghaei Avatar answered Mar 23 '23 10:03

Reza Aghaei