繁体   English   中英

C# rdlc 报错LocalProcessingException

[英]C# rdlc report error LocalProcessingException

我花了很长时间弄清楚这一点。 我以正确的方式传递参数(遵循网络上的一些教程)。 并且 .rdlc 也为我的参数(=Parameters!myparam1.Value)使用报告窗口贴上了正确的符号(表达式)。

计划是在我单击按钮后加载报告。 但是当它尝试设置参数时就会发生错误。 这是代码:

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

这是堆栈跟踪:

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()

任何帮助是appriciated。 谢谢你。

除了程序员错误之外,最可能的问题是报表查看器版本的向后兼容性。 每次使用 GUI 编辑报告时,通常都需要该解决方法。

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

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

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

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

  5. 保存更新并再次运行程序。 报告应该有效。

Yoy 可以像这样使用这个参数。 试试这个它肯定会帮助你

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM