Can we find out how many data rows were returned by RenderReport?

1 Answer 36 Views
Report Viewer - Blazor
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Daniel asked on 14 Mar 2022, 05:10 PM

I'm exporting a report programmatically to PDF using code like this:

                var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
                var deviceInfo = new System.Collections.Hashtable();
                var reportSource = new Telerik.Reporting.UriReportSource();
                reportSource.Uri = "<My report path>.trdp";

//Various parameters are set
                object ParmValue;
                ParmValue = "<My value>";
                reportSource.Parameters.Add("<My parameter name>", ParmValue);

                Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);

After this I save the result into SQL server for retrieval later. For these reports I always get a result object back even if there are no data rows returned from the database query the report makes (it still has headers/footers/etc. but no details). What I'd like to do is determine if there weren't any data rows returned and take alternate action myself. 

Is there a way to determine how many data rows were retrieved by the report? The only solution I can come up with at the moment is querying the database twice; first without the report being involved to see if the database query will returns any rows; and then again by the RenderReport method if there's data to report on. That isn't efficient though. Is there something in the report objects that will tell me if there was no data returned to the report?

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 17 Mar 2022, 12:24 PM

Hello Daniel,

If you would like to change the report layout based on whether it receives any data records, I suggest utilizing Bindings, Conditional Formatting, and No Data Message in the report definition. The corresponding Expression may use the Aggregate Functions, for example, Count to check whether there are records returned by the query.

Generally, the data used by the report is fetched when processing it. For that reason, it is not available in the report definition items that are in Telerik.Reporting namespace. The data is in the Processing items in the Telerik.Reporting.Processing namespace. For that reason, you may access the data only in the Report events and Report item events.

If the Report, or other data item has been assigned an empty DataSource, the ItemDataBinding event of the Report/data item will be called, but the ItemDataBound won't be fired. When the data source returns at least one record, both events will be fired. You may use this to check whether there is data returned or not.

Note that if you use TRDP or TRDX reports, you will have to Unpackage or Deserialize therm to attach the corresponding event handlers.

It may be still easier and cheaper to perform an additional query to the database that returns an aggregate result, i.e Count of records in order to check whether the report will receive any data.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
Report Viewer - Blazor
Asked by
Daniel
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Todor
Telerik team
Share this question
or