为什么导出的报告为空?
问题描述:
我有一个空的导出报告,我不知道为什么会发生这种情况。为什么导出的报告为空?
我已经在我的方法之一,下面的代码:
ReportDocument report = new ReportDocument();
report.Load(pathToReport);
成功加载后,我将使用下一个方法我所有的参数:
public static void SetParameterValue(ReportDocument document,string parName,object value)
{
ParameterFieldDefinition f = document.DataDefinition.ParameterFields[parName];
ParameterDiscreteValue v = new ParameterDiscreteValue();
v.Value = value;
f.CurrentValues.Add(v);
f.DefaultValues.Add(v);
f.ApplyDefaultValues(f.DefaultValues);
f.ApplyCurrentValues(f.CurrentValues);
}
和上面的电话后,我打电话:
private void ApplyNewServer(ReportDocument report)
{
//Initialize subreports connection first
foreach (ReportDocument subreport in report.Subreports)
{
foreach (Table crTable in subreport.Database.Tables)
{
TableLogOnInfo logOnInfo = crTable.LogOnInfo;
logOnInfo.ConnectionInfo.ServerName = "serverName";
logOnInfo.ConnectionInfo.UserID ="user";
logOnInfo.ConnectionInfo.Password ="password";
logOnInfo.ConnectionInfo.IntegratedSecurity = false;
crTable.ApplyLogOnInfo(logOnInfo);
}
}
foreach (Table crTable in report.Database.Tables)
{
TableLogOnInfo logOnInfo = crTable.LogOnInfo;
logOnInfo.ConnectionInfo.ServerName = "serverName";
logOnInfo.ConnectionInfo.UserID = "user";
logOnInfo.ConnectionInfo.Password = "password";
logOnInfo.ConnectionInfo.IntegratedSecurity = false;
crTable.ApplyLogOnInfo(logOnInfo);
}
VerifyDatabase(report);
foreach (IConnectionInfo info in report.DataSourceConnections)
{
if (info.Type == ConnectionInfoType.CRQE)
{
info.SetConnection("databaseName", string.Empty,"user","password");
}
}
}
而且VerifyDatabase作用:
private void VerifyDatabase(ReportDocument report)
{
report.SetDatabaseLogon(user, pwd, dbName, String.Empty);
report.VerifyDatabase();
}
在此之后,我尝试导出我的报告:
public bool ExportReport(ReportDocument reportDocument, string exportType, string exportPath, string fileName)
{
//creating full report file name
fileName = fileName + "." + exportType;
//creating storage directory if not exists
if (!Directory.Exists(exportPath))
Directory.CreateDirectory(exportPath);
//creating new instance representing disk file destination
//options such as filename, export type etc.
DiskFileDestinationOptions diskFileDestinationOptions = new DiskFileDestinationOptions();
ExportOptions exportOptions = reportDocument.ExportOptions;
switch (exportType)
{
case "rpt":
{
diskFileDestinationOptions.DiskFileName = exportPath + fileName;
exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
exportOptions.ExportFormatType = ExportFormatType.CrystalReport;
exportOptions.DestinationOptions = diskFileDestinationOptions;
break;
}
}
try
{
//trying to export input report document,
//and if success returns true
reportDocument.Export();
return true;
}
catch (Exception err)
{
return false;
}
}
我的报表导出但在预览模式下没有任何数据,甚至没有从设计模式的字段。
有人请帮忙!我是Crystal Reports的新手。
答
如果你正在创建一个RPT文件,你的导出代码工作正常。
对于“空白”报告,我会查看参数代码。无论何时,当您自动执行报告并且没有获取任何数据时,与参数设置和/或记录选择标准(多次使用参数集)相关的时间为99.9%。
看那里。
答
我想我的问题是因为报告是在Web.csproj中创建的,并且IIS中没有读/写权限,因此无法读取和写入Windows的Temp文件夹...我会检查这个事情了,我会回来的答案。
在你发布的示例代码中,你永远不会调用'ExportReport'。您是否使用调试程序浏览了代码?你正在默默捕捉异常,这通常是一件坏事,特别是在分析问题时。 – 2010-11-16 15:27:35