为什么导出报告为空?

时间:2010-11-16 15:22:22

标签: c# crystal-reports

我有一个空的导出报告,我不知道为什么会发生这种情况。

我的一个方法中有以下代码:

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

验证数据库执行:

    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的新手。

2 个答案:

答案 0 :(得分:0)

如果您正在创建一个RPT文件,那么您的导出代码工作正常。

对于“空”报告,我会查看参数代码。只要您自动生成报告并且没有获得任何数据,就会有99.9%的时间与参数设置和/或记录选择标准相关(多次使用参数设置)。

看那里。

答案 1 :(得分:0)

我认为我的问题是因为报告是在Web.csproj中创建的,并且IIS中没有读取/写入权限,以便能够读取和写入Windows的Temp文件夹...我会检查这个东西我会回来的。