locked
Pass Parameter Values to Reportviewer in VB.NET RRS feed

  • Question

  • User-360635291 posted

    Please help a newbie learn.  I set up a very simple test.  I have one aspx page with one TextBox1 and one Button1 and one ReportViewer1.

    The report viewer works just fine if the dataset is not looking for a parameter value.  I don't want the users to add the values in the report parameters.

    All I want to do is pass the value from the TextBox1 to the ReportViewer1 which is waiting for the @param value?  I've seached for days and can not find a solution.  I know I have to import Microsoft.Reporting.WebForms but the OnClick code I can not get.  The closest thing that I could find was something like this and it did not work for me.

            Dim p(0) As ReportParameter
            p(0) = New ReportParameter("param", TextBox1.Text)
            ReportViewer1.LocalReport.SetParameters(p)
            ReportViewer1.DataBind()
            ReportViewer1.LocalReport.Refresh()

    Please HELP!!!Cry

    How would you pass two parameters int his example?

    Wednesday, September 19, 2012 2:03 PM

Answers

  • User-360635291 posted

    Here is the answer to this question.  This guy was nice enough to make a video showing how it's done.

    https://www.youtube.com/watch?v=1mn8KoEjKzo&feature=g-all-u

    Dim Param1 As New ReportParameter
    Param1.Name = "ParamFromReport" '*** The actual name of the parameter in the report ***
    Param1.Values.Add(TextBox1.Text)
    ReportViewer1.ServerReport.SetParameters(New ReportParameter() {Param1})
    'The above line if for Reports sitting at SQL and the below is for local reports
    'ReportViewer1.LocalReport.SetParameters(New ReportParameter() {Param1})



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 10, 2012 1:53 PM

All replies

  • User423701163 posted

    1. Create a data set (DataSet1) that points to your report data that has also a parameter (Parameter1) if necessary. This is for the case when your parameter affects the SQL statement that pulls report data as well (in this case the command string may be something like: SELECT * from myTable where myField <= :Parameter1).

    2. Create a report that uses DataSet1 and has a parameter called ReportParameter1

    3. Use the following code:

        Dim rds As New ReportDataSource
        Dim oTableAdapter As New DataSet1TableAdapters.yourTableAdapter
        Dim m_DataSet = New yourProjectName.DataSet1
    
        oTableAdapter.Connection.ConnectionString = your connection string
    
        oTableAdapter.Fill(m_DataSet.Tables(0), TextBox1.Text)
    
        rds.Name = m_DataSet.DataSetName
        rds.Value = m_DataSet.Tables(0)
       
        ReportViewer1.KeepSessionAlive = True
        With ReportViewer1.LocalReport
          .DataSources.Clear()
          .DataSources.Add(rds)
          .Refresh()
          .SetBasePermissionsForSandboxAppDomain(New PermissionSet(PermissionState.Unrestricted))
        End With
    
        m_DataSet.Dispose()
        m_DataSet = Nothing
        oTableAdapter.Dispose()
        oTableAdapter = Nothing
    
        Dim myParam As New ReportParameter("ReportParameter1", TextBox1.Text)
        ReportViewer1.LocalReport.SetParameters(myParam)
    
        rds = Nothing
        myParam = Nothing

    Regards, M.R.

    Thursday, September 20, 2012 2:24 PM
  • User-360635291 posted

    Here is the answer to this question.  This guy was nice enough to make a video showing how it's done.

    https://www.youtube.com/watch?v=1mn8KoEjKzo&feature=g-all-u

    Dim Param1 As New ReportParameter
    Param1.Name = "ParamFromReport" '*** The actual name of the parameter in the report ***
    Param1.Values.Add(TextBox1.Text)
    ReportViewer1.ServerReport.SetParameters(New ReportParameter() {Param1})
    'The above line if for Reports sitting at SQL and the below is for local reports
    'ReportViewer1.LocalReport.SetParameters(New ReportParameter() {Param1})



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 10, 2012 1:53 PM