Crystal Report : Missing parameter values in the PDF export

7.6k views Asked by At

I have a visual studio 2008 with .NET 3.5 Web application. I am using crystal report version 10.5 for the reporting. I need to export the crystal report to the PDF file. When I export the report in the PDF file without setting the parameter, it is working fine. But when I pass a parameter into the report it shows the following issue

"Missing parameter values."

  at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
   at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
   at Web.Manager.GetReport() in c:\Model 2008 \mypage.aspx.cs:line 267

Below is the code

  private void GetReport(Dataset dsModel)
    {
        ReportDocument crReportDocument;
        crReportDocument = new ReportDocument();
        crReportDocument.Load(Server.MapPath("MyReport.rpt"));

        ParameterValues pvValues = new ParameterValues();
        ParameterDiscreteValue pdvDiscreteValue = new ParameterDiscreteValue();
        pdvDiscreteValue.Value = Session["myname"].ToString();
        pvValues.Add(pdvDiscreteValue);
        ParameterFieldDefinitions pfdDefinitions = crReportDocument.DataDefinition.ParameterFields;
        ParameterFieldDefinition prdDefinition = pfdDefinitions["Parameter1"];
        prdDefinition.ApplyCurrentValues(pvValues);


            crvManagerByBank.Visible = true;
            crReportDocument.SetDataSource(dsModel);
            crvManagerByBank.ReportSource = crReportDocument;
            string Fname = ConfigurationSettings.AppSettings["TempFolder"];
            Fname = Fname + Session.SessionID.ToString() + ".pdf";
            ExportOptions crExportOptions = new ExportOptions();
            DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();

            crDiskFileDestinationOptions.DiskFileName = Fname;
            crExportOptions = crReportDocument.ExportOptions;
            crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
            crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

            crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

            try
            {
                crReportDocument.Export(); -- Showing error in this line
            }
            catch (Exception)
            {

                throw;
            }

            Response.ClearContent();
            Response.ClearHeaders();

            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=" + Fname);
            Response.TransmitFile(Fname);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            Response.Flush();
            Response.Close();
            System.IO.File.Delete(Fname);

        }
    }

Throwing the exception when it calls the Export() function.

1

There are 1 answers

0
Pankaj Saha On

Thank you everyone for you support. I have added the below line before export() function.

try
            {
crReportDocument.SetParameterValue("Parameter1", Convert.ToString(Session["myname"]));

                crReportDocument.Export(); 
            }
            catch (Exception)
            {

                throw;
            }