C# 为什么导出的报告为空?

C# 为什么导出的报告为空?,c#,crystal-reports,C#,Crystal Reports,我有一个空的导出报告,我不知道为什么会发生这种情况 我的一个方法中包含以下代码: ReportDocument report = new ReportDocument(); report.Load(pathToReport); 加载成功后,我使用下一种方法设置所有参数: public static void SetParameterValue(ReportDocument document,string parName,object value) {

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

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

    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%的时间都与参数设置和/或记录选择条件有关(其中很多次使用参数集)


看那里。

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

对于“空”报告,我将查看参数代码。任何时候,当您在自动生成报告时,如果没有任何数据,99.9%的时间都与参数设置和/或记录选择条件有关(其中很多次使用参数集)


看那里。

我想我的问题是因为报告是在Web.csproj中创建的,IIS中没有对此的读/写权限,无法对Windows的临时文件夹进行读写。。。我会检查这件事,然后再回答。

我想我的问题是因为报告是在Web.csproj中创建的,IIS中没有读/写权限,无法读取和写入Windows的临时文件夹。。。我会检查这件事,然后我会给出答案。

在您发布的示例代码中,您从未调用过
ExportReport
。您是否使用调试器逐步完成了代码?您正在默默地捕获异常,这通常是一件坏事,尤其是在分析问题时。在您发布的示例代码中,您从未调用
ExportReport
。您是否使用调试器逐步完成了代码?您正在默默地捕捉异常,这通常是一件坏事,尤其是在分析问题时。