Visual Studio Developer Center > Visual Studio Forums > Visual Studio Report Controls > Using Parameters in a TextBox on an rdlc Report
Ask a questionAsk a question
 

AnswerUsing Parameters in a TextBox on an rdlc Report

  • Tuesday, November 03, 2009 6:28 PMbspiro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I have what I think is a simple question that I just can't find the answer to.  I have a report that I want to include a few fields at the top of the report.  These are variables being used in the rest of the application.  I am trying to use parameters in order to have those fields show up in a textbox on the report.

    The following code does not produce any errors and I can see the report and the others items (such as lines and Textbox with just text as the value) but it also does not show the value in the textbox (the value is blank).  I think the problem may be where I am defining the Parameters but I am not sure where else to put it.  The two lines that I have remarked do not seem to make any difference.

    Any help would be appreciated.

    Code:

    Imports System.Collections

    Public Class Form1

     

     

        Private Sub ReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportViewer1.Load

            Dim UserName As String = "Tom"

            Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter

            params(0) = New Microsoft.Reporting.WinForms.ReportParameter("UserName", UserName, False)

            'Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "ReportTest3.report1.rdlc"

            'Me.ReportViewer1.LocalReport.ReportPath = "report1.rdlc"

            Me.ReportViewer1.ServerReport.Refresh()

        End Sub

    End Class


    Value in TectBox2:
    =Parameters!UserName.Value

    parameter Box

    I have setup a Parameter and called it UserName, which is a string and is marked as hidden.

     


    bspiro
    • Moved byChao KuoMSFTFriday, November 06, 2009 11:04 AM (From:Visual Basic Language)
    •  

Answers

  • Monday, November 09, 2009 4:44 AMRajaSekhar-Navigator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    hi bsprio,

    you can use the following code, the code which you posted doesnt have setparameters,

     Dim RptParam1(0) As ReportParameter
            'Setting Name to Report Parameter
            ' Parameter Name defined here should be exactly similar to name defined in          ' Report
            RptParam1(0) = New ReportParameter("RptParam1")
            'Assigning Values to Parameter
            RptParam1(0).Values.Add(“Test Value”)
            'Finally Add The Parameter To Report Viewer
            reportViewer1.LocalReport.SetParameters(RptParam1)

    the code is working fine for me

    Hope this helps

    -Raja sekhar K
    • Marked As Answer bybspiro Monday, November 09, 2009 5:59 PM
    •  

All Replies

  • Tuesday, November 03, 2009 10:25 PMMalange Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    can you post you parameters code here, please? I think should set it as true:

    params(0) = New Microsoft.Reporting.WinForms.ReportParameter("UserName", UserName, True)

    in your parameters, do u have @?

    Don't judge me, just Upgrade me. Thanks!
  • Friday, November 06, 2009 5:20 PMJohnFL Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code


    Try This

    Public Sub ProjectionReport()
            'Set the Processing  mode for the ReportViewer to Remote
            ReportsForm.ReportViewer1.ProcessingMode = ProcessingMode.Remote
    
            Dim ServerReport As ServerReport
            ServerReport = ReportsForm.ReportViewer1.ServerReport
    
            'Get a reference to the default Credentials
            Dim Credentials As System.Net.ICredentials
            Credentials = System.Net.CredentialCache.DefaultCredentials
    
            'Get a reference to the report server credentials
            Dim rsCredentials As ReportServerCredentials
            rsCredentials = ServerReport.ReportServerCredentials
    
            'Set the report server URL and Report Path
            ServerReport.ReportServerUrl = _
                New Uri("http://myServer/ihreportserver")
            ServerReport.ReportPath = _
                "/Reports/HotelsForecastAnalysisTabular"
    
            'Create the report parameters for the report
            Dim myAccessCode As String = MainForm.ToolStripLabelAccessCode.Text
            Dim ParamAccessCode As New ReportParameter()
            ParamAccessCode.Name = "AccessCode"
            ParamAccessCode.Values.Add(myAccessCode)
    
            'Set the report Parameters for the report
            Dim Parameters() As ReportParameter = {ParamAccessCode}
            ServerReport.SetParameters(Parameters)
            'Refresh the report
            ReportsForm.ReportViewer1.RefreshReport()
        End Sub
    
    
    

    John
  • Friday, November 06, 2009 10:12 PMbspiro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I believe I posted all of the code above.  I tried to paste a screen shot of the parameter but the image seemed to be blank so i specified how the parameter was setup.  I believe I tried setting the false to true (or removing it completely and it had no affect but I will try again.

    I do not have an @ in the parameter.
    bspiro
  • Friday, November 06, 2009 10:14 PMbspiro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Do I really need to setup the reportviewer as Remote?  I do see some code at the bottom that seems to be setting the value of the paramter.  This may also be the step that I am missing so i will try that over the weekend. 
    bspiro
  • Monday, November 09, 2009 4:44 AMRajaSekhar-Navigator Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    hi bsprio,

    you can use the following code, the code which you posted doesnt have setparameters,

     Dim RptParam1(0) As ReportParameter
            'Setting Name to Report Parameter
            ' Parameter Name defined here should be exactly similar to name defined in          ' Report
            RptParam1(0) = New ReportParameter("RptParam1")
            'Assigning Values to Parameter
            RptParam1(0).Values.Add(“Test Value”)
            'Finally Add The Parameter To Report Viewer
            reportViewer1.LocalReport.SetParameters(RptParam1)

    the code is working fine for me

    Hope this helps

    -Raja sekhar K
    • Marked As Answer bybspiro Monday, November 09, 2009 5:59 PM
    •