locked
Binding C# Entity Framework dataset to Remote SSRS (.rdl) from inside ASP.NET MVC 5 RRS feed

  • Question

  • User523169010 posted
    //My Controller.
    public ActionResult ExpectedSales(string[] Quarter, int Year, string[] Divisions)
            {
                
                    try
                    {
                        int myQtr = GFIHelper.GetQuarterNumber(Quarter);
                        string ProductDivisions = Repository.getMyDivision(@User.Identity.Name, Divisions);
                        
                        //All ReportViewer parameters are returned with GFISSRSReportViewer.GetReportViewer();
                        //.....................................................................
                        ReportViewer MyReportViewer = GFISSRSReportViewer.GetReportViewer();
                        MyReportViewer.ServerReport.ReportPath = GFIReportsPath.GetSalesManagementReportURL("ExpectedSales");
                        //.....................................................................
                      
                        
                      
                        //GFISSRSReportViewer.GetCommonParaList includes only PrintedDate.
                        //.....................................................................
                        List<ReportParameter> paramList = GFISSRSReportViewer.GetCommonParaList(GFIHelper.TitleCase(User.Identity.Name));
                        //.....................................................................
                        string nextyear = "";
                        if (myQtr == 1)
                            nextyear = Convert.ToString(Year + 0);
                        else
                            nextyear = Convert.ToString(Year + 1);
                        //Printedby and report name must be assigned here
                        //.....................................................................
                        string rptname = "EXPECTED SALES" + "@" + string.Join("+", Divisions) + "@" + string.Join("+", Quarter) + " : " + Year + (Year == Convert.ToInt32(nextyear) ? "" : " - " + nextyear);
                        rptname = rptname.Replace("@", Environment.NewLine);
                        paramList.Add(new ReportParameter("ReportName", rptname, false));
                        //.....................................................................
    
                        paramList.Add(new ReportParameter("YearPara", Convert.ToString(Year), false));
                        paramList.Add(new ReportParameter("QuarterStringPara", Convert.ToString(myQtr), false));
                        paramList.Add(new ReportParameter("DivisionsPara", ProductDivisions, false));
    
                        MyReportViewer.ServerReport.SetParameters(paramList);
    
                        
                        ViewBag.ReportViewer = MyReportViewer;
                        return PartialView("_ReportLayout");
                    }
                    catch (Exception ex)
                    {
                        return PartialView(ex.Message + ex.StackTrace);
                    }
                
            }
            
    //My Layout for Report
    
    @using ReportViewerForMvc;
    @using System.Web.UI.WebControls;
    
    <br />
    <br />
    <div class="myReportViewer md-block" flex="100" flex-gt-sm>
        <div class="myReportViewerHead">
            <span>Report Viewer</span>
        </div>
        <md-divider style="background-color:orange;"></md-divider>
        @if (ViewBag.ReportViewer != null)
        {
            @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new
                   {
                       frameBorder = "0",
                       Width = Unit.Percentage(100),
                       Height = 600,
                       ScrollBars="Yes",
                       SizeToReportContent=true
                   })
        }
    </div>

    I have been working on a C# / ASP.NET MVC 5 / AngualrJs project with SQL Server 2008 R2 Reporting Server (

    .rdl

    ). I actually want to bind dataset from inside ASP.NET MVC to the ReportViewer object. But I don't know exactly how to accomplish this.

    Can anyone help me with this?

    Currently my reports are using datasets from inside the VS Report Server project and working fine, but I just need to pass the dataset from C# code.

    I am simply passing parameters to the remote report server. But In my controller I also want to provide the processed dataset.

    Thanks

    Monday, April 17, 2017 11:12 AM

All replies

  • User-2057865890 posted

    Hi mjkhan,

    I actually want to bind dataset from inside ASP.NET MVC to the ReportViewer object. But I don't know exactly how to accomplish this.

    Can anyone help me with this?

    Currently my reports are using datasets from inside the VS Report Server project and working fine, but I just need to pass the dataset from C# code.

    I am simply passing parameters to the remote report server. But In my controller I also want to provide the processed dataset.

    Add Entity Data Model.

    Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add. A popup window will come (Entity Data Model Wizard) > Select EF designer from database > Next > Chose your data connection > select your database > next > Chose Entity Framework version > Next > Choose Database Objects and Settings > Finish.

    Select ADO.net Entity Data Model under data

    Select EF designer from database

    Chose Entity Framework version

    Choose Database Objects and Settings

    Bind Report Viewer code snippets

    List<MVCReportViwer.Customer> customers = null;
    using (MVCReportViwer.MyDatabaseEntities dc = new MVCReportViwer.MyDatabaseEntities())
    {
        customers = dc.Customers.OrderBy(a => a.CustomerID).ToList();
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/rptCustomer.rdlc");
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportDataSource rdc = new ReportDataSource("MyDataset", customers);
        ReportViewer1.LocalReport.DataSources.Add(rdc);
        ReportViewer1.LocalReport.Refresh();
    }

    How to display rdlc report in ReportViewer control into an MVC web application.

    How to Bind a Report to an Entity Framework

    Best Regards,

    Chris

    Tuesday, April 18, 2017 6:45 AM
  • User523169010 posted

    Chris Zhao, what about Report Server Side how do I prepare my report, I mean Should I have datasource and dataset if yes then with what names because my scenario uses remote SSRS server where the reports are already stored, just want to send the datasets along with the parameters.

    Tuesday, April 18, 2017 7:25 AM
  • User523169010 posted

    Matt, I am looking to assign dataset from C# code to Remote Report Server .rdl file stored at server side not locally. Can you please help me with that.

    Wednesday, April 19, 2017 4:27 AM
  • User-696616202 posted

    Matt, I am looking to assign dataset from C# code to Remote Report Server .rdl file stored at server side not locally. Can you please help me with that.



    Hello @mjkhan, did you find any answer for this? (Processing Mode = Remote)

    Saturday, January 23, 2021 7:36 PM