2008-11-19 61 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

这可能发生的另一种方式是如果您使用共享数据集并且包含报告未使用的数据集。每个报告都必须在本地为每个共享数据集定义自己的参数版本。因此,如果您已将数据集作为数据源之一包含在内,并且未明确定义此特定报告如何将参数传递给该数据集,则会发生此错误。

相关问题