[英]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 編輯報告時,通常都需要該解決方法。
通過右鍵單擊解決方案資源管理器中的文件來打開報告 (.rdlc) 文件。 然后選擇“打開方式...” 選擇 XML(文本)編輯器。 (報告作為 XML 文檔打開。
找到標記並確保它指向舊版本的命名空間。 (通常,這是命名空間定義中的年份,您必須在這里更改。我將我的更改為 2008。我認為這就是 VS2010 到 VS2015 使用的。)
接下來,找到 ReportSections 及其對應的子 ReportSection 標記。 刪除這些元素(標簽)及其對應的結束標簽即 /ReportSections、/ReportSection
然后找到 ReportParametersLayout 並刪除它及其內部內容。
保存更新並再次運行程序。 報告應該有效。
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.