how to detect empty report

Stimulsoft Reports.NET discussion
Post Reply
sw
Posts: 22
Joined: Fri Jan 26, 2007 10:26 pm

how to detect empty report

Post by sw »

Hi,

I am testing to generate report from database using dynamic query. Sometime, the query will not return any data and then if I export the data as image, I will get image with no data on it. Is there a way that I can detect when there is no data returned from the query?

thanks,

sw
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

how to detect empty report

Post by Edward »

Please use IsEmpty property of the Datasource.

Thank you.
sw
Posts: 22
Joined: Fri Jan 26, 2007 10:26 pm

how to detect empty report

Post by sw »

Thank you, Edward,

When should I check the IsEmpty property? It always return false when I check IsEmpty after call to render(). Could you please provide some code snippet?

sw

Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

how to detect empty report

Post by Edward »

Please inform me when do you want to check a query? After rendering the report or in the code of the report to make a decision to render something or not?
In other words what is the goal of the checking a query?

Thank you.
sw
Posts: 22
Joined: Fri Jan 26, 2007 10:26 pm

how to detect empty report

Post by sw »

In my application, I need to export pdf report at predefined time intervals. The data were retrieved from a database. Some times, the sql query defined in datasource of the report does not contain any data. In that case, I do want to generate a report without any data. The question is how to determine whether a report has any data or not.

sw
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

how to detect empty report

Post by Edward »

Please do the following steps:

1. Define a variable in the Dictionary of the report with bool type. For example IsReportHasData.

2. In the BeforePrint event of the page of the report please add the following code:

Code: Select all

IsReportHasData = !Categories.IsEmpty;
3. In your Application please check this variable after rendering the report:

Code: Select all

            report.Render();
            if ((bool)report["IsReportHasData"] == true)
            {
                MessageBox.Show("DataSource is not empty");
            }
            else
            {
                MessageBox.Show("DataSource is empty");
            }           
Thank you.


ssdev23
Posts: 10
Joined: Fri Jun 13, 2008 2:18 am

how to detect empty report

Post by ssdev23 »

Hi edward, this case and solution is close to my problem at hand.

My case is to determine

If a table.column has a value/is not empty
then proceed on printing report
Else display a warning on a message box like "Data on column_name is not existing. Pls. correct"

May i know your thoughts on doing it?


Thx.
ssdev23
Posts: 10
Joined: Fri Jun 13, 2008 2:18 am

how to detect empty report

Post by ssdev23 »

I added some codes on the Page BeforePrintEvent:
if (Table.Column == null){
MessageBox.Show("Data on column_name is not existing. Pls. correct");
Page1.Enabled = false;}
And on AfterPrintEvent:
Page1.Enabled = true;
THis shows the message box okay but I should not set Page1.enabled = false because the report still needs to be printed (labels, etc.) except the fetched data.

how will i do that?

Thanks!
Post Reply