Issues Setting RDLC Datasource to Object

前端 未结 5 457
长情又很酷
长情又很酷 2020-12-30 01:53

Background:

I\'ve been tasked with converting an Access database application to ASP.Net C# MVC. This is my first MVC application.

There are

5条回答
  •  伪装坚强ぢ
    2020-12-30 02:07

    I was able to add an object as a datasource in VS 2017 without the report Wizard. [Winforms app using c#] [PS I am a NOOB, so there is going to be mistakes etc, but i hope this helps with giving a direction.] steps I used:

    part A 1. create an object that represents the data e.g.: object / model class in my case it is an appointment object

     class FutureVisitsModel
        {
            public DateTime StartDate {get; set;}
            public string Client_Id { get; set; }
            public string Treatment_Desc { get; set; }
            public string Service_Code { get; set; }
    
            public FutureVisitsModel()
            {
                DateTime startdate = StartDate;
                String clinetid = Client_Id;
                String treatmentdesc = Treatment_Desc;
                String serviceCode = Service_Code;
            }
        }
    

    Part B: create report 2. Added report to solution: right clicked solution, select add new item and chose report enter image description here 3. opened the blank report 4. from toolbox, drag n drop a table to the report 5. a dialogue opens to choose a data source 6. select the object from your solution [ ypu will be looking for the class you created in part A

    Part C: create a report viewer form 7. on solution explorer create a new form "formRptViewer" 8. open the form and add report viewer control 9. If you dont have the control in your tool box, you will need to install the report viewer package from nugget or install via package manger console. webforms version : Install-Package Microsoft.ReportingServices.ReportViewerControl.WebForms winforms version: Install-Package Microsoft.ReportingServices.ReportViewerControl.WinForms

    9.1 set the control of the report viewer to public in solution explorer click the dropdown next to your formRptViewer to see the files that make up the form edit this file: formRptViewer.Designer.cs change the controll pf the reprtviewer to public public Microsoft.Reporting.WinForms.ReportViewer ReportViewer1;

    part D: create a datatable and send it to report 10. create a datatable DataTable dataTableFutureVisits = new DataTable(); [you will need to fill the datatable with y our own data] 11. add using statement using Microsoft.Reporting.WinForms; 12. set the data source and create a new instance of the report viewer

    ReportDataSource rs = new ReportDataSource();
                rs.Name = "DataSet1";
                rs.Value = dataTableFutureVisits;
                FormRptViewer frm = new FormRptViewer();
                frm.ReportViewer1.LocalReport.DataSources.Clear();
                frm.ReportViewer1.LocalReport.DataSources.Add(rs);
                frm.ReportViewer1.LocalReport.ReportEmbeddedResource = "ChiroRecallList.RptFutureVisits.rdlc";
                // name the report with date
                frm.ReportViewer1.LocalReport.DisplayName = "Your File Name Goes Here" + "_" + DateTime.Now.ToString("yyyyMMdd HH:mm");
                frm.ShowDialog();
    

    Part E: updating the report: adding columns to the datatable and show them in the report [ also forks for removing a column]

    1. add a column to your datatable
    2. change your object class to reflect the data [ as in part A ]
    3. open the report and delete the dataset [not data source ]
    4. in solution explorer: there is a properties dropdown expand that
    5. expand the datasources folder
    6. delete the data source that is named after your model screen shot

    7. clean and rebuild solution screenshot

    8. open the report and right click on your datasource and add new dataset screen shot

提交回复
热议问题