VB.Net Report viewer parameters

ⅰ亾dé卋堺 提交于 2021-02-11 14:20:13

问题


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:

  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.


回答1:


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

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.




回答2:


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



回答3:


Maybe accidentally you have set available values for parameter to just null or some other values in report.rdlc. If so goto parameter properties and set Available Values to None and try again.




回答4:


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.




回答5:


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


来源:https://stackoverflow.com/questions/27806245/vb-net-report-viewer-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!