C#rdlc报告错误LocalProcessingException

时间:2012-08-01 22:44:40

标签: c# asp.net .net rdlc

我很想知道这一点。我以正确的方式传递参数(遵循Web上的一些教程)。并且.rdlc对我的参数也有正确的表示法(表达式)(= Parameters!myparam1.Value)使用报告窗口进行decalred。

计划是在点击按钮后加载报告。但是当它尝试setParameters时,错误就会发生。这是代码:

private void button4_Click(object sender, EventArgs e)
{
  ReportViewer reportViewer1 = new ReportViewer();
  reportViewer1.LocalReport.ReportPath = "AddressLabelReport.rdlc";
  reportViewer1.ProcessingMode = ProcessingMode.Local;
  reportViewer1.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter  ("myparam1", "my value1", false), new ReportParameter("myparam2", "my value2", false) }); 
  reportViewer1.RefreshReport();
}

这是StackTrace:

Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
  Message="An error occurred during local report processing."
  Source="Microsoft.ReportViewer.WinForms"
  StackTrace:
       at Microsoft.Reporting.WinForms.LocalReport.CompileReport()
       at Microsoft.Reporting.WinForms.LocalReport.SetParameters(IEnumerable`1 parameters)
       at TextBookLabelForm.Form1.button4_Click(Object sender, EventArgs e) in C:\Projects\TextBookLabelForm\TextBookLabelForm\Form1.cs:line 204
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at TextBookLabelForm.Program.Main() in C:\Projects\TextBookLabelForm\TextBookLabelForm\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

任何帮助都是适当的。谢谢。

3 个答案:

答案 0 :(得分:1)

伴随程序员错误的最可能的问题是ReportViewer版本的向后兼容性。每次您使用GUI编辑报告时,通常都需要此解决方法。

  1. 通过在解决方案资源管理器中右键单击该报告(.rdlc)文件。然后选择“打开方式...”,选择XML(文本)编辑器。 (该报告以XML文档的形式打开。

  2. 找到标签,并确保它指向旧版本的名称空间。 (通常,这是您必须在此处更改名称空间定义的年份。我将我的名称更改为2008。我认为这就是VS2010至VS2015所使用的。)

  3. 接下来,找到ReportSections及其对应的子ReportSection标记。删除这些元素(标签)及其相应的结束标签,即/ ReportSections,/ ReportSection

  4. 然后找到ReportParametersLayout并将其及其内部内容删除。

  5. 保存更新并再次运行程序。该报告应该起作用。

答案 1 :(得分:0)

您可以像这样使用此参数。尝试这个肯定会帮助你

ReportParameter[] parms = new ReportParameter[n];
parms[0] = new ReportParameter("myparam1", "my value1");
parms[1] = new ReportParameter("myparam2", "my value2");
this.reportViewer1.LocalReport.SetParameters(parms);
this.reportViewer1.RefreshReport();

答案 2 :(得分:0)

尝试检查报告中的参数名称。如果使用其他名称添加它们,则会抛出该异常。当报告无效时,它也会抛出此异常,但我怀疑是这种情况。