2012-06-28 24 views
3

我正在加載我的報告,我已經完成了使用SSRS,代碼(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); 
      } 

感謝

+0

你是什麼意思報告是空的?你的意思是你傳遞數據集的參數沒有記錄? – nunespascal

+0

@nunespascal正是我的意思 – jozef

回答

2

數據集是內部的報告。沒有外部API來查找給定報表參數的特定數據集返回的記錄數。

有可以採取的解決問題的兩種方法:

1。使用LocalReport

在C#代碼中創建DataSet,檢查它是否有行,然後將其作爲數據源提供給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格式下載您的報告。這將爲您提供每組數據的原始數據。在這裏你可以檢查返回的行數。

+0

使用第二種解決方案將報告下載爲CSV,我如何知道每個數據源的原始數據?!!,以便檢查行數?!!在此先感謝 – jozef

+0

將您的報告保存爲CSV並查看,爲每個數據源它將寫出數據。統計CSV文件中的行數應該是微不足道的。 – nunespascal

1

這是我的忍者做法。

設置每一個控制隱藏屬性設置爲隱藏控制表達式當這些數據沒有記錄:

=Rownumber("TransactionsByAccountAndEffDate") = 0 

在報告我還插入一個文本框,並設置其隱藏屬性,讓人們知道什麼時候的報告沒有數據:

enter image description here

=Rownumber("TransactionsByAccountAndEffDate") > 0 

後來,當我產生一個沒有報告數據,所有的控制將被隱藏,這使得文件的微小尺寸:

enter image description here

我創建了一個代碼的報告中,我簡單的檢查文件的大小,看看它的微小後:

var length = new System.IO.FileInfo(path).Length;