我正在加载我使用SSRS完成的报告,代码(C#),但是我需要检查报告是否为空!!!
我怎么能得到它?!! 我使用的代码是:
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);
}
提前致谢
答案 0 :(得分:2)
DataSet是报告的内部信息。没有外部API可以查找特定数据集为给定报告参数返回的记录数。
您可以采取两种方法来解决问题:
1。使用LocalReport
使用C#代码创建数据集,检查它是否有行,然后将其作为数据源提供给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());
参考:Dynamic Reports with Reporting Services
2。以CSV格式下载报告。这将为您提供参数集的每个DataSource的原始数据。在这里,您可以检查返回的行数。
答案 1 :(得分:1)
这是我的忍者做法。
将每个控件的Hidden属性设置为当DataSet没有记录时隐藏控件的Expression:
=Rownumber("TransactionsByAccountAndEffDate") = 0
在报告中我还插入一个TextBox并设置其隐藏属性,让人们知道报告何时没有数据:
=Rownumber("TransactionsByAccountAndEffDate") > 0
然后当我生成没有数据的报告时,所有控件都将被隐藏,这会使文件的大小变小:
我在代码中创建报告后,我只需检查文件大小,看看它是否很小:
var length = new System.IO.FileInfo(path).Length;