VB.Net 报表查看器参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27806245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:37:47  来源:igfitidea点击:

VB.Net Report viewer parameters

vb.netparametersfilterreportreportviewer

提问by NetCollector

I added a Parameter to report.rdlc called "ReportTitle". It is text and allows blank values and nulls. I have tried different ways to pass the parameter value to no avail. This is what I've tried so far:

我向 report.rdlc 添加了一个名为“ReportTitle”的参数。它是文本并且允许空值和空值。我尝试了不同的方法来传递参数值无济于事。这是我迄今为止尝试过的:

  Dim parReportParam1 As New ReportParameter("ReportTitle", "THIS IS MY TITLE")
  ReportViewer1.LocalReport.SetParameters(New ReportParameter() {parReportParam1})

Does not work!

不起作用!

    Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
    params(0) = New Microsoft.Reporting.WinForms.ReportParameter("ReportTitle", "THIS IS MY TITLE")
    ReportViewer1.LocalReport.SetParameters(params)

Nothing!

没有!

    Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
    params(0) = New Microsoft.Reporting.WinForms.ReportParameter
    params(0).Name = "ReportTitle"
    params(0).Values.Add("THIS IS MY TITLE")
    ReportViewer1.LocalReport.SetParameters(params)

Nope!

不!

I don't know what to try anymore. Do I have to set something on the reportviewer or on the designer to allow parameter values. Any help is greatly appreciated it.

我不知道该尝试什么了。我是否必须在报表查看器或设计器上设置某些内容以允许参数值。非常感谢任何帮助。

采纳答案by Tomek

I found The Aswer, You need to remember to put parameters after you pick the path to the Report never before.

我找到了 The Aswer,你需要记住在你选择之前从未选择过的 Report 路径之后输入参数。

I had exacly the same problem, everything was fine till I put parameters to the Raport and I had spent two hours before I found the cause.

我遇到了完全相同的问题,一切都很好,直到我将参数添加到 Raport 并且我花了两个小时才找到原因。

回答by CajunThreePutt

This worked for me:

这对我有用:

    Dim paramStoreNo As New ReportParameter("StoreNo", iSTORE_NO)
    Dim reportparameters() As ReportParameter = {paramStoreNo}
    InventoryTableAdapter.Fill(Me.DataSet1.Inventory, iSTORE_NO)
    Me.ReportViewer1.LocalReport.SetParameters(reportparameters)
    Me.ReportViewer1.RefreshReport()

回答by Mojtaba Rezaeian

Maybe accidentally you have set available values for parameter to just nullor some other values in report.rdlc. If so goto parameter properties and set Available Valuesto Noneand try again.

也许您不小心将参数的可用值设置为 justnullreport.rdlc. 如果是这样,请转到参数属性并设置Available Values为并重None试。

回答by Azure

If your problem is that you cant see your parameter value at your report, Can you try adding a refresh in your report viewer code page.

如果您的问题是无法在报告中看到参数值,您可以尝试在报告查看器代码页中添加刷新。

Add this at the end of your code

在你的代码末尾添加这个

Reportviewer.localreport.refresh()

The problem might be because the page loaded before the application finished passing the values, so refresh it so it can reload with the parameter values at hand.

问题可能是因为在应用程序完成传递值之前加载了页面,因此刷新它以便它可以重新加载手头的参数值。

回答by Hadi

I used the following code and it works fine:

我使用了以下代码,它工作正常:

For Each param As WinForms.ReportParameterInfo In ReportViewer1.LocalReport.GetParameters()


If param.name = "ReportTitle" Then

 ReportViewer1.LocalReport.SetParameters(New WinForms.ReportParameter(param.Name, "THIS IS MY TITLE"))

End If

Next

Me.ReportViewer1.RefreshReport()