2008-11-19 64 views
6

我試圖直接打印RDLC文件而沒有顯示Microsoft Report Viewer,我按照MSDN's example但現在每次調用「Render」方法我的LocalReport類實例拋出「運行報告所需的一個或多個參數沒有被指定」。例外。運行報告所需的一個或多個參數沒有指定

任何人都可以告訴我哪些參數是我錯過的嗎?或者我如何找到關於這個異常的更多細節?

 LocalReport report = new LocalReport(); 
     report.ReportPath = System.Windows.Forms.Application.StartupPath + "\\" + rdlcFileName; 
     report.EnableExternalImages = true; 

     ReportParameter[] reportParams = new ReportParameter[] 
     { 
      new ReportParameter("LogoAddress", settings.LogoFileName), 
      new ReportParameter("FooterValue", settings.InvoicesFooter) 
     }; 
     report.SetParameters(reportParams); 

     report.DataSources.Add(new ReportDataSource("Invoice", new PrintableInvoice[] { invoice })); 
     report.DataSources.Add(new ReportDataSource("InvoiceItem", invoiceItems)); 

     Warning[] warnings; 
     try 
     { 
      string deviceInfo = 
       "<DeviceInfo>" + 
       " <OutputFormat>EMF</OutputFormat>" + 
       " <PageWidth>8.5in</PageWidth>" + 
       " <PageHeight>11in</PageHeight>" + 
       " <MarginTop>0.25in</MarginTop>" + 
       " <MarginLeft>0.25in</MarginLeft>" + 
       " <MarginRight>0.25in</MarginRight>" + 
       " <MarginBottom>0.25in</MarginBottom>" + 
       "</DeviceInfo>"; 

      m_streams = new List<Stream>(); 
      report.Render("Image", deviceInfo, _CreateStream, out warnings); 

      foreach(Stream stream in m_streams) 
       stream.Position = 0; 
     } 
     catch(Exception ex) 
     { 
      System.Diagnostics.Debug.WriteLine(ex.Message); 
     } 

和_CreateStream是:

private Stream _CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) 
    { 
     Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create); 
     m_streams.Add(stream); 
     return stream; 
    } 
+1

回覆發現:http://social.msdn.microsoft.com/Forums/zh/vsreportcontrols/thread/7cce3c91-f876-417a-81cc-10e10dde0e40 – MilkyWayJoe 2012-02-15 20:07:07

回答

15

如果傳遞的參數值,像參數空字符串=「」 它會給你一個錯誤

我剛剛發現我花了一段

+1

謝謝!這可能需要我很長時間才能弄清楚。 :)(剛剛得到了完全相同的錯誤) – 2012-12-13 08:36:07

+0

如果我真的想傳遞空字符串,解決方法是什麼? – JoshNaro 2015-02-02 18:24:45

5

在參數屬性中允許爲null將解決此問題。

3

原因:本地報告不允許你傳遞空或空參數,我不知道爲什麼,但它會拋出異常。

修復:一種方式,以找出哪些參數引起異常是調用 var result = report.LocalReport.GetParameters(); 方法,在它的具有 result[0].State 屬性,如果它的值 MissingValidValue 它會導致異常參數結果的數組。

例:以上

var rv = new ReportViewer { ProcessingMode = ProcessingMode.Local }; 
     rv.LocalReport.ReportPath = Server.MapPath("~/PrintForms/FromForm.rdlc"); 
     rv.LocalReport.Refresh(); 

     string mimeType; 
     string encoding; 
     string filenameExtension; 
     string[] streamids; 
     Warning[] warnings; 

     rv.LocalReport.SetParameters(new ReportParameter("ClientName", "გიორგი გიორგაძე")); 
     rv.LocalReport.SetParameters(new ReportParameter("Account", "888"));var streamBytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 
     return File(streamBytes, mimeType); 

代碼工作正常,但如果你改變參數相加行:

rv.LocalReport.SetParameters(new ReportParameter("Account", null)); 

帳戶ReportParameter的狀態值會MissingValidValue,它會導致異常。

+2

這應該是被接受的答案。 – BG100 2016-09-05 14:55:29

1

如果你真的需要傳遞一個空字符串作爲值,你可以做如下因素:

  • 打開參數屬性(右鍵單擊報告數據面板上的參數);
  • 標記允許空白值(「」)複選框。

這解決了我的事情。

0

這可能發生的另一種方式是如果您使用共享數據集並且包含報告未使用的數據集。每個報告都必須在本地爲每個共享數據集定義自己的參數版本。因此,如果您已將數據集作爲數據源之一包含在內,並且未明確定義此特定報告如何將參數傳遞給該數據集,則會發生此錯誤。

相關問題