问题
I'm loading my reports that I have done using SSRS,by code(C#),but i need to check if report is empty or not!!!
how can i get that?!! my code that Im using is:
if (!string.IsNullOrEmpty(RptInstance.FileName))
{
string ReportName = RptInstance.FileName.Replace(".rpt", "");
reportViewer.ServerReport.ReportPath = string.Format("{0}{1}", Settings.Default.ReportPath, ReportName);
reportViewer.ServerReport.SetParameters(paramList);
reportViewer.ServerReport.Timeout = Timeout;
string mimeType, encoding, extension, deviceInfo;
string[] streamIds = null;
Warning[] warnings = null;
deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";
byte[] bytes = reportViewer.ServerReport.Render(RptInstance.PDF ? "PDF" : "Excel", deviceInfo, out mimeType, out encoding, out extension, out streamIds, out warnings);
RptInstance.State = true;
//SaveData(Report.FileName, bytes, string.Format(@"C:\temp\{0}.{1}", ReportName, isPdf ? "pdf" : "xlsx"));
SaveData(string.Format("{0}_{1}.{2}", ReportName, Guid.NewGuid(), RptInstance.PDF ? "pdf" : "xlsx"), bytes, DirectoryName);
}
thanks in advance
回答1:
DataSets are internal to a report. There is no external API to find the number of records returned by a particular dataset for a given report parameters.
There are two approaches you can take to solve the problem:
1 . Use a LocalReport
Create your DataSet in C# code, check if it has rows, and then give this as a DataSource to SSRS.
ReportDataSource ds = new ReportDataSource(dsName, data);
ReportGenerator gen = new ReportGenerator(data, dsName);
reportViewer.Reset();
reportViewer.LocalReport.DataSources.Add(ds);
reportViewer.LocalReport.DisplayName = displayName;
reportViewer.LocalReport.LoadReportDefinition(gen.GeneraReport());
Refer : Dynamic Reports with Reporting Services
2 . Download your report as a CSV. This will give you the raw data for each DataSource for your set of parameters. Here you can check the number of rows returned.
回答2:
Here is my ninja way of doing it.
Set every controls Hidden property to an Expression that hides the control when the DataSet has no records:
=Rownumber("TransactionsByAccountAndEffDate") = 0
In the Report I also insert a TextBox and set its Hidden property to let people know when the report has no data:
=Rownumber("TransactionsByAccountAndEffDate") > 0
Then when I generate the report that has no data, all the controls will be hidden and this makes the size of the file tiny:
After I've created the report in code I simple check the file size, to see if its tiny:
var length = new System.IO.FileInfo(path).Length;
来源:https://stackoverflow.com/questions/11247466/check-my-ssrs-report-if-its-empty-from-code