Page 1 of 1

how to detect empty report

Posted: Tue Apr 24, 2007 12:25 am
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

how to detect empty report

Posted: Tue Apr 24, 2007 2:28 am
by Edward
Please use IsEmpty property of the Datasource.

Thank you.

how to detect empty report

Posted: Tue Apr 24, 2007 10:31 pm
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


how to detect empty report

Posted: Wed Apr 25, 2007 1:54 am
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.

how to detect empty report

Posted: Wed Apr 25, 2007 9:35 am
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

how to detect empty report

Posted: Wed Apr 25, 2007 10:46 am
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.



how to detect empty report

Posted: Mon Oct 20, 2008 10:57 pm
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.

how to detect empty report

Posted: Tue Oct 21, 2008 3:26 am
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!