Search code examples
asp.net-mvccrystal-reports

Missing Parameters in Crystal Reports


Like so many others I'm also having trouble with missing parameters in Crystal Reports. I've examined the other responses in regards to this issue but so far have not been able to come up with a solution. Any help is appreciated. Here's what I have so far. I'm trying to export to a stream in an ASP.NET MVC Controller Action.

public ActionResult ExportCustomers(int workNum)
        {
            RequestListViewModel requestListViewModel = new RequestListViewModel();
      var x = (stored procedure results).ToList();

            var z = ToDataTable(x);

            ReportDocument rd = new ReportDocument();
            rd.Load(Path.Combine(Server.MapPath("/Reports"), "ReportFormWorkRequest.rpt"));

            rd.SetParameterValue("@WorkReqNum", workNum);

            rd.SetDataSource(z);      

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

            Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            stream.Seek(0, SeekOrigin.Begin);
            return File(stream, "application/pdf", "WorkRequests.pdf");
        }

On the line containing "rd.ExportToStream" I get the error: Missing parameter values. Because I have not tried to generate a Crystal Report from ASP.NET MVC before it's probably something basic I'm missing.

Pete


Solution

  • After examining this more closely, I found there was 1 parameter on the Main Report plus 7 additional parameters on the subreports. The following code shows the whole action with the missing parameters. While it does answer the question posed in the post it currently is not returning data correctly to the browser. That may be dealt with in another post. Thanks to those of you who responded to my question.

    Pete

     RequestListViewModel requestListViewModel = new RequestListViewModel();
                var x = (stored procedure results).ToList();
    
                var z = ToDataTable(x);
    
                ReportDocument rd = new ReportDocument();
    
                rd.Load(Path.Combine(Server.MapPath("/Reports"), "ReportFormWorkRequest.rpt"));
    
                rd.SetDataSource(z);
    
                rd.SetParameterValue("@WorkReqNum", workNum);
    
                rd.SetParameterValue("@Subparam1", 0, rd.Subreports[0].Name.ToString());
                rd.SetParameterValue("@Subparam2", 0, rd.Subreports[1].Name.ToString());
                rd.SetParameterValue("@Subparam3", 0, rd.Subreports[2].Name.ToString());
                rd.SetParameterValue("@Subparam4", 0, rd.Subreports[3].Name.ToString());
                rd.SetParameterValue("@Subparam5", 0, rd.Subreports[3].Name.ToString());
                rd.SetParameterValue("@Subparam6", 0, rd.Subreports[3].Name.ToString());
                rd.SetParameterValue("@Subparam7", 0, rd.Subreports[4].Name.ToString());
    
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();
    
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
    
                return File(stream, "application/pdf");