c# - 检查我的 SSRS 报告如果代码为空

标签 c# web-services ssrs-2008 reportviewer2008

我正在通过代码 (C#) 加载我使用 SSRS 完成的报告,但我需要检查报告是否为空!!!

我怎样才能得到它?!! 我使用的代码是:

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);
            }

提前致谢

最佳答案

数据集是报表内部的。没有外部 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 格式下载您的报告。这将为您提供参数集的每个数据源的原始数据。您可以在此处检查返回的行数。

关于c# - 检查我的 SSRS 报告如果代码为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11247466/

相关文章:

reporting-services - 计算行组的行结果数

c# - 将 C# Web 服务参数传递给 PHP 应用程序

web-services - .NET 4.5 中的 HttpResponseMessage 发生了什么,有替代方案吗?

c# - 正则表达式逗号分隔的字符串验证

c# - 我有一个变量,当我将它递增 1 时它保持为 0?

Android ksoap2 可空类型

reporting-services - SSRS 本地报告失败 - 错误 "An error has occurred during report processing"

reporting-services - 如何更改SSRS中参数下拉框的宽度?

c# - 删除另一个文件后无法创建另一个文件,因为它已被另一个进程使用

c# - Unity 每次点击都会增加 90º