开发者

Why is exported report empty?

开发者 https://www.devze.com 2023-01-25 14:50 出处:网络
I have an empty exported report and I don\'t know why is happening this. I have the following code in one of my methods:

I have an empty exported report and I don't know why is happening this.

I have the following code in one of my methods:

    ReportDocument report = new ReportDocument();
    report.Load(pathToReport);

After loading successfully, I set all my parameters using next method:

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

And after the above call, I call:

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

And VerifyDatabase does:

    private void VerifyDatabase(ReportDocument report)
    {
        report.SetDatabaseLogon(user, pwd, dbName, String.Empty);
        report.VerifyDatabase();
    }

After this, I try to export my report:

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

And my report is exported but has no data in preview mode, not even the fields from design mode.

Someone, please help ! I am new to Crystal Reports.


If you're getting an RPT file created, your export code is working fine.

For the "empty" report, I would look at the parameter code. Anytime you're automating a report and you don't get any data, it's 99.9% of the time related to the setting of parameters and/or record selection criteria (which many times uses the parameters set).

Look there.


I suppose my problem is because the reports are created in the Web.csproj and there are no read/write permissions in IIS for this, to enable reading and writing to the Windows's Temp folder... I'll check this thing out and I'll come back with an answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消