传递参数给报表c#

问题描述 投票:0回答:2

当我尝试向报告传递参数时出现错误。

Microsoft.ReportViewer.WebForms.dll 中发生类型为“Microsoft.Reporting.WebForms.LocalProcessingException”的未处理异常。

我的代码:

ReportViewer reportViwer = new ReportViewer();
reportViwer.ProcessingMode = ProcessingMode.Local;

reportViwer.LocalReport.ReportEmbeddedResource = "MyReport.Report1.rdlc";

List<ReportParameter> listReportParameter = new List<ReportParameter>();

listReportParameter.Add(new ReportParameter("Name", "Test"));

reportViwer.LocalReport.SetParameters(listReportParameter);

错误出现在“SetParameters”中。

说明:

Microsoft.Reporting.WebForms.LocalProcessingException was unhandled
  HResult=-2146233088
  Message=An error occurred during local report processing.
  Source=Microsoft.ReportViewer.WebForms
  StackTrace:
       at Microsoft.Reporting.WebForms.LocalReport.CompileReport()
       at Microsoft.Reporting.WebForms.LocalReport.SetParameters(IEnumerable`1 parameters)
       at MyReport.Form1.button1_Click(Object sender, EventArgs e) in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Form1.cs:line 37
       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(IntPtr 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 MyReport.Program.Main() in e:\_Organizado\AERON\Projetos\Visual Studio C#\Relatorio\MyReport\Program.cs:line 19
       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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: Microsoft.Reporting.DefinitionInvalidException
       HResult=-2146233088
       Message=The definition of the report 'Main Report' is invalid.
       Source=Microsoft.ReportViewer.Common
       ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=pvInvalidDefinition&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=9.0.21022.8
       SkipTopLevelMessage=false
       StackTrace:
            at Microsoft.Reporting.ReportCompiler.CompileReport(CatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ReportSnapshotBase& snapshot)
            at Microsoft.Reporting.StandalonePreviewStore.StoredReport.CompileReport()
            at Microsoft.Reporting.StandalonePreviewStore.StoredReport.get_Snapshot()
            at Microsoft.Reporting.StandalonePreviewStore.GetCompiledReport(CatalogItemContext context, Boolean rebuild, ReportSnapshotBase& snapshot)
            at Microsoft.Reporting.LocalService.CompileReport(CatalogItemContext itemContext, Boolean rebuild)
            at Microsoft.Reporting.WebForms.LocalReport.CompileReport()
       InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException
            HResult=-2146233088
            Message=The report definition is not valid.  Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded.
            Source=Microsoft.ReportViewer.Common
            ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsProcessingError&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=9.0.21022.8
            SkipTopLevelMessage=false
            StackTrace:
                 at Microsoft.ReportingServices.ReportProcessing.ReportPublishing.Phase1(CatalogItemContext reportContext, Byte[] definition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, String& description, String& language, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, Boolean& hasExternalImages, Boolean& hasHyperlinks)
                 at Microsoft.ReportingServices.ReportProcessing.ReportPublishing.CreateIntermediateFormat(CatalogItemContext reportContext, Byte[] definition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, PublishingErrorContext errorContext, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions, String& description, String& language, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks)
                 at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CompileReport(CatalogItemContext reportContext, Byte[] reportDefinition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, PublishingErrorContext errorContext, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions, String& reportDescription, String& reportLanguage, ParameterInfoCollection& parameters, DataSourceInfoCollection& dataSources, UserLocationFlags& userReferenceLocation, ArrayList& dataSetsName, Boolean& hasExternalImages, Boolean& hasHyperlinks)
                 at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.CreateIntermediateFormat(CatalogItemContext reportContext, Byte[] reportDefinition, CreateReportChunk createChunkCallback, CheckSharedDataSource checkDataSourceCallback, AppDomain compilationTempAppDomain, Boolean generateExpressionHostWithRefusedPermissions)
                 at Microsoft.Reporting.ReportCompiler.CompileReport(CatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ReportSnapshotBase& snapshot)
            InnerException: 

非常感谢任何帮助!!

c# visual-studio-2012 report
2个回答
0
投票

在报告中添加名称为“Name”和“Test”的参数,然后重试。

如果已经完成,请尝试更改

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

致:

this.reportViewer1.LocalReport.ReportPath = "MyReport.Report1.rdlc";

您也可以尝试以下操作:

Uncheck
“Name”参数的
Internal
属性。

检查报告中参数的属性。 (右键单击报告窗格,选择参数。)

UNCHECK
-
internal
-


0
投票

我解决了这个问题。

我的报告中发生了这种情况,因为我在测试中放置了两个参数,而我只是将数据传递给其中之一。

在我的报告中创建了“名称”和“测试”参数,我只是传递“名称”的值。

listReportParameter.Add (new ReportParameter ("Name", this.textBox1.Text)); 

当我删除报告中的“测试”参数时,它起作用了。

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.