开发者

Crystal Reports exception when calling ExportToDisk

I'm getting some weird behavior with Crystal Reports (version distributed with Visual Studio 2008). I can view the report normally, but attempts to use ExportToDisk fail with the following exception:

CrystalDecisions.CrystalReports.Engine.InvalidArgumentException:

This group section cannot be printed because its condition field is nonexistent or invalid. Format the section to choose another condition field. Error in File C:\DOCUME~1\gbuehler\LOCALS~1\Temp\Report {2FD9516D-0FD4-4D20-A326-D21EB762EB9E}.rpt: Invalid group condition. ---> System.Runtime.InteropServices.COMException (0x8000020B):

This group section cannot be printed because its condition field is nonexistent or invalid. Format the section to choose another condition field. Error in File C:\DOCUME~1\developer\LOCALS~1\Temp\Report {2FD9516D-0FD4-4D20-A326-D21EB762EB9E}.rpt: Invalid group condition. at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) --- End of inner exception stack trace --- 开发者_StackOverflow社区 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.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName) at LSPayroll.MainForm.btnSendCanadian_Click(Object sender, EventArgs e) in C:\Documents and Settings\developer\My Documents\Visual Studio 2008\Projects\MyProject\MyProject\MainForm.cs:line 277

A cursory search for Invalid Group Condition returns other users looking for solutions and recommendations to recreate the report. Can someone give a logical reason why the report can be viewed normally, but ExportToDisk fails with an exception?

Not sure if it helps, but this is the code I'm using to create the report document and export:

// build a crystal reports document in memory and use the crystal 
// reports library to export as a PDF
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetDataSource(data);
reportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "payroll.pdf");


Struggled to find a solution to this problem

The solution that worked for me

In the statement

reportDocument.SetDataSource(data);

ensure that 'data' is a reference to a DataSet and not a DataTable.


I'm using a DataTable, and it works fine:

public ActionResult ReporteUsuarios() {
        DataTable dt = new DataTable();
        try {
            SqlConnection con = (SqlConnection)seguridad.Database.Connection;
            con.Open();
            SqlCommand cmd = new SqlCommand("select nombre from usuarios", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);
            con.Close();
        } catch (Exception ex) {
            throw new HttpException(500, "Hubo un problema con la base de datos. " + ex.StackTrace.ToString());
        }

        ReportClass rpt = new ReportClass();
        rpt.FileName = Server.MapPath("/Reports/Usuarios.rpt");
        rpt.Load();
        rpt.SetDataSource(dt);

        Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        return File(stream, "application/pdf", "Usuarios.pdf");
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜