Return a response to indicate “No Data” via the ReportExecution.RenderReport() API method

こ雲淡風輕ζ 提交于 2019-12-13 07:16:20

问题


I am looking for a tip, trick or hack that will allow a return of an empty byte array, an out warning flag or some other indicator to let the caller of ReportExecution2005.RenderReport() be aware that no data was returned for the report.


回答1:


I believe that I know what you're doing now, but correct me if I'm wrong.

You created the dataset and the required parameters in the report and set the stored procedure there. Then you just pass the parameters from code and then you just render the report which causes SSRS to automatically fill the dataset with respect to the parameters.

This is a good approach but this causes you to have no knowledge of the datasource until the report is rendered.

I believe the solution to your problem is to generate the datasource outside the reporter, so executing the procedure from code. Then you have access to any information about the dataset before sending it to the reporter. So if the procedure returned no data this allows you to not render the report at all. And when you do render the report, you won't gave to execute the procedure anymore (efficiency).

  • The easiest way to achieve this is to use the Local Reporting Services (often refered to as rdlc).

    There is no need to use a shared datasource because you have the wanted dataset already. You can just pass the datatable to the reporter and it will render correctly without needing to execute the procedure anymore.

    There are many tutorials that should make this easy for you, here is a simple example: Using a Local Reporting Services 2008 Report with an ADO.NET Data Set

  • If you really insist on using the older Reporting Services then it'll be slightly more complicated to setup but it's still possible. Here is detailed tutorial: Using an ADO.NET DataSet as a Reporting Services Data Source

Before rendering the report, you simply fill your dataset by executing the procedure. And check whether or not you wish to continue rendering the report.
Example:

SqlDataAdapter daVendor = new SqlDataAdapter();
daVendor.SelectCommand = cmd;
DataSet dsVendors = new DataSet();
daVendor.Fill(dsVendors);

if(dsVendors.Any()){
//Render the report (passing the dataset to the reporter) and attach it to the mail.
}
else {
//Don't render the report and create corresponding message to send as email.
}

I strongly suggets using the Local Reporting Services. You don't want to add extra functionality anyway, as you're only sending it as attachment to an email.

I hope this helps you along, if you have any more trouble just leave a comment.




回答2:


Use visibility to mimic this. Check count of your dataset and if its 0 dont show anything and then also create a text box that says no data available or something like that and set the visibility to only show when count is 0. Hope this make sense.



来源:https://stackoverflow.com/questions/35492756/return-a-response-to-indicate-no-data-via-the-reportexecution-renderreport-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!