1
我有一個.NET 3.5 Web應用程序的Visual Studio 2008。我正在使用Crystal報告版本10.5進行報告。我需要將水晶報告導出到PDF文件。當我在不設置參數的情況下導出PDF文件中的報告時,它工作正常。但是,當我將參數傳遞到報表中出現下面的問題Crystal Report:缺少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);
}
}
拋出異常時,它調用導出()函數。
打開MyReport.rpt文件並檢查那裏的報告參數。也許你可以發佈他們的打印屏幕。你必須填寫所有這些參數。奇怪的是:在代碼中我看不到任何參數名稱。我錯過了什麼? – heringer