如何修复错误将参数传递给报告rdlc winform时未处理本地处理异常?

Sag*_*ran 6 c# winforms

我正在做大学项目。那样,他们想要一个真实的证明。为此,我计划传递TextBox字符串进行报告。

我用谷歌搜索在winform中传递参数。然后我逐步进行了此过程。我实现了。

步:

1:在Visual Studio 2010中,打开.rdlc文件,然后打开“报表数据”窗口(如果看不到此窗口,请转到“视图”菜单将其打开);

2:右键单击“参数”节点,并添加新的参数,即:将其命名为“ content”;

3:在您的.rdlc文件中,添加一个名为tbContent的文本框,并将其字段express设置为:

= Parameters!content.Value

4:转到包含您的reporterview控件的Form文件,然后添加以下代码:

       this.reportViewer1.LocalReport.ReportEmbeddedResource
Run Code Online (Sandbox Code Playgroud)

=“ TestReport.Report1.rdlc”;ReportParameter rp = new ReportParameter(“ content”,this.textBox1.Text); this.reportViewer1.LocalReport.SetParameters(new ReportParameter [] {rp}); this.reportViewer1.RefreshReport();

5:然后可以将参数从表单上的文本框传递到.rdlc文件;

我添加了using Microsoft.Reporting.WinForms;程序集参考。

 this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";

            ReportParameter rp = new ReportParameter("content", this.textBox1.Text);
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
            this.reportViewer1.RefreshReport();  
Run Code Online (Sandbox Code Playgroud)

但这引发了异常:


this.reportViewer1.LocalReport.SetParameters(new ReportParameter [] {rp}); 处未处理本地处理异常。线。

这是剪贴板中的完整错误:

  Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
  Message=An error occurred during local report processing.
  Source=Microsoft.ReportViewer.WinForms
  StackTrace:
       at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       at Microsoft.Reporting.WinForms.LocalReport.SetParameters(IEnumerable`1 parameters)
       at Report.Form1.Form1_Load(Object sender, EventArgs e) in D:\Jagadeeswaran\Project\Report\Report\Form1.cs:line 38
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.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.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       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 Report.Program.Main() in D:\Jagadeeswaran\Project\Report\Report\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ApplicationException
       Message=The report definition for report 'D:\Jagadeeswaran\Project\Report\Report\bin\Debug\~/Report1.rdlc' has not been specified
       Source=Microsoft.ReportViewer.Common
       StackTrace:
            at Microsoft.Reporting.PreviewStore.GetCompiledReport(CatalogItemContextBase context, Boolean rebuild, Byte[]& reportDefinition, ControlSnapshot& snapshot)
            at Microsoft.Reporting.LocalService.GetCompiledReport(CatalogItemContextBase itemContext, Boolean rebuild, ControlSnapshot& snapshot)
            at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       InnerException: System.IO.DirectoryNotFoundException
            Message=Could not find a part of the path 'D:\Jagadeeswaran\Project\Report\Report\bin\Debug\~\Report1.rdlc'.
            Source=mscorlib
            StackTrace:
                 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
                 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
                 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
                 at Microsoft.ReportingServices.StandalonePreviewStore.GetReportDefinition(ReportID reportId)
                 at Microsoft.Reporting.PreviewStore.GetCompiledReport(CatalogItemContextBase context, Boolean rebuild, Byte[]& reportDefinition, ControlSnapshot& snapshot)
            InnerException: 
Run Code Online (Sandbox Code Playgroud)

Dev*_*erX 4

设置这个:

this.reportViewer1.ProcessingMode = 
    Microsoft.Reporting.WinForms.ProcessingMode.Local;
Run Code Online (Sandbox Code Playgroud)

并改变这一点:

this.reportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc" 
Run Code Online (Sandbox Code Playgroud)

this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
Run Code Online (Sandbox Code Playgroud)