Search code examples
c#crystal-reports

Get number of records from Crystal Report in C# code


I have a C# Winforms application that creates some reports (in Crystal Report XI), sometimes by individual requests, sometimes in massive requests (5 or more reports).

I need to skip empty reports in some cases (not every time), so I would like to find a way to know how many lines my main query (a stored procedure) is returning (without re executing the stored procedure because it could take a lot of time)

I've tried to pass an output parameter to the stored procedure but it doesn't work, I can't find the output parameter in the ParameterFields property of the CrystalReport object in my code.

I've tried to reach the Rows property but I get an error:

'Report.Rows.Count' threw an exception of type System.Runtime.InteropServices.COMException'

and I m not sure that this is the rows of the report data.

I don't care about subreport, I'd like to focus only on the main one.

Anyone could help?


Solution

  • //Main Report    
    CrystalDecisions.CrystalReports.Engine.ReportDocument rd; //rd is a report with subreports which gets no data
    
        CrystalDecisions.ReportAppServer.Controllers.RowsetCursor rowsetCursor = null;
        rd.ReportClientDocument.RowsetController.CreateCursor(null, null, 0);
        if (rowsetCursor.IsEOF)
        {
            bResult = false; //main report contains no data
        }
    

    from SAP.