Quantcast
Channel: Crystal Reports
Viewing all articles
Browse latest Browse all 1507

ASP.Net 2017 - MVC 5 Crystal Subreports

$
0
0

Good day tech gurus,

l now know how to create a crystal report in MVC 5 and exporting it to pdf through a view on browser, but l have no clue how to create a sub-report and call it on master report so that the comprehensive report can also be exported to pdf. Any one who knows how this can be done please help. Here is my scenario: l have two models, SchemeBook which then becomes the master report and SchemeBookObjectives which then becomes the Subreport:

    public class SchemeBook
    {
        [Key]
        public Int64 SchemeID { get; set; }
        public int ClassID { get; set; }
        public int SubjectID { get; set; }
        public int SchoolYear { get; set; }
        public int SchoolTerm { get; set; }
        public Int64 Userid { get; set; }
    }

    public class SchemeBookObjective
    {
        [Key]
        public Int64 ObjectiveID { get; set; }
        public string Objective { get; set; }
        public Int64 SchemeID { get; set; }
        public Int64 Userid { get; set; }
    }

Here are the report views:

        public ActionResult RptTPStudentSchemeBook()
        {
            Int64 scmID = Convert.ToInt64(HttpContext.Session["scmId"]);
            Int64 scmYR = Convert.ToInt64(HttpContext.Session["scmYr"]);
            Int64 scmTM = Convert.ToInt64(HttpContext.Session["scmTerm"]);
            object[] parameters = { scmID };
            ReportDocument rd = new ReportDocument();
            rd.Load(Path.Combine(Server.MapPath("~/Reports/RptTPStudentSchemeBook.rpt")));
            rd.SetDataSource(objReportView.RptTPStudentSchemeBook(parameters));
            RptTPStudentSchemeObjective(scmID);


            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            Stream str = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            str.Seek(0, SeekOrigin.Begin);


            string SavedFileName = string.Format("Scheme_{0}_{1}_{2}_{3}", Session["FName"], Session["LName"], scmYR, scmTM);
            return File(str, "application/pdf", SavedFileName);
        }

        public ActionResult RptTPStudentSchemeObjective(Int64 scmID)
        {

            object[] parameters = { scmID };
            ReportDocument rd = new ReportDocument();
            rd.Load(Path.Combine(Server.MapPath("~/Reports/RptSchemeObjective.rpt")));
            rd.SetDataSource(objSchemeBookObjective.GetAll(parameters));

 
            Stream st = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            st.Seek(0, SeekOrigin.Begin);
            string SavedFileName = string.Format("Scheme_{0}", DateTime.Now);
            return File(st, "application/pdf", SavedFileName);
        }

RptTPStudentSchemeObjective is a subreport linked to master report RptTPStudentSchemeBook based on SchemeID which is obtained through a session variable scmID.

l am getting error message:

Server Error in '/' Application.

Error in File RptTPStudentSchemeBook 6840_15604_{25FA1B33-61FE-4CAF-9443-5AA13AD6EDF4}.rpt:
Unable to connect: incorrect log on parameters. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.Runtime.InteropServices.COMException: Error in File RptTPStudentSchemeBook 6840_15604_{25FA1B33-61FE-4CAF-9443-5AA13AD6EDF4}.rpt:
Unable to connect: incorrect log on parameters.

Source Error: 



Line 187:            Response.ClearHeaders();
Line 188:
Line 189:            Stream str = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Line 190:            str.Seek(0, SeekOrigin.Begin);
Line 191:            //string SavedFileName = string.Format("Scheme_{0}", DateTime.Now);

 Source File:  C:\Users\TMATIWURE\source\repos\CollegeSys\CollegeSys.WebUI\Controllers\ReportController.cs    Line:  189 

Stack Trace: 


 I AM ALSO VERY WILLING TO DROP CRYSTAL REPORTS FOR RDLC OR SSRS AS LONG AS I GET A GOOD STEP BY STEP LINK WHICH CAN TAKE ME THROUGH FROM THE BEGINNING.


Viewing all articles
Browse latest Browse all 1507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>