Crystal Report:PDF导出中缺少参数值

时间:2015-06-11 10:58:48

标签: c# .net visual-studio crystal-reports crystal-reports-2008

我有一个带有.NET 3.5 Web应用程序的visual studio 2008。我使用水晶报告版本10.5进行报告。我需要将水晶报告导出到PDF文件。当我在PDF文件中导出报告而不设置参数时,它工作正常。但是当我将参数传递给报告时,它显示了以下问题

"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

以下是代码

  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);

        }
    }

调用Export()函数时抛出异常。

1 个答案:

答案 0 :(得分:-1)

谢谢大家的支持。我在export()函数之前添加了以下行。

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

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

                throw;
            }