none
Visual Basic 2008 report problem RRS feed

  • Question

  • Hi everyone!!!
    My problem looks like this.
    I have a report(rdlc) and a form1. On the form1 there is a textbox. I put a textbox on the report too.
    How can I pass the value from the textbox on my form to the textbox on the report???
    What code do i have to write in the textbox on the report to give it the value of the textbox on my form?

    Please help!!!
    Thursday, August 7, 2008 11:10 AM

Answers

  • Ok, to do this, you need to create a parameter in your report.  

    Right click bank area, choose paramters.  Add a parameter...give it a name.

    Then in the textbox you want to show the parameters value. put in the folowing expression

    =Parameters!ParamName.Value

    "ParamName" should of course be replaced with the actual name You gave the parameter

    Now in your code,  you have to programatically hand the parameter to the report.

     
     
            Dim reportParam As New ReportParameter("ParamName", txtBox.Text)  
     
            ReportViewer1.LocalReport.SetParameters(New ReportParameter() {reportParam}) 

    above is the VB code to delcare a reportparameter.

    Each report parameter needs to know it's name, the name you gave it in the .rdlc.  And of course it needs a value, in this case it's the value of the textbox in question.
    Then give your report parameter to the report.
    Living my life at 123mph in 11.15 seconds
    • Edited by Blasty Thursday, August 7, 2008 2:17 PM edited
    • Marked as answer by Tibore Thursday, August 7, 2008 11:55 PM
    Thursday, August 7, 2008 2:15 PM

All replies

  • Ok, to do this, you need to create a parameter in your report.  

    Right click bank area, choose paramters.  Add a parameter...give it a name.

    Then in the textbox you want to show the parameters value. put in the folowing expression

    =Parameters!ParamName.Value

    "ParamName" should of course be replaced with the actual name You gave the parameter

    Now in your code,  you have to programatically hand the parameter to the report.

     
     
            Dim reportParam As New ReportParameter("ParamName", txtBox.Text)  
     
            ReportViewer1.LocalReport.SetParameters(New ReportParameter() {reportParam}) 

    above is the VB code to delcare a reportparameter.

    Each report parameter needs to know it's name, the name you gave it in the .rdlc.  And of course it needs a value, in this case it's the value of the textbox in question.
    Then give your report parameter to the report.
    Living my life at 123mph in 11.15 seconds
    • Edited by Blasty Thursday, August 7, 2008 2:17 PM edited
    • Marked as answer by Tibore Thursday, August 7, 2008 11:55 PM
    Thursday, August 7, 2008 2:15 PM
  • does this work in vb 2005 the same way?
    i wrote visual basic 2008 but actually i need it for 2005.
    If it works the same way,then i have a problem...

    Dim reportParam As New ReportParameter("param", TextBox1.Text)

    the ReportParameter is underlined (type ReportParameter is not defined)

    Just to be sure...i have to paste this code to the reportviewer?
    Thursday, August 7, 2008 2:54 PM
  • I didn't really put this example up as a "cut and paste" answer.  It was just to show you basically how it's done.  I couldn't begin to tell you where to put the code, since you'd have to know your own solution.

    If ReportParameter is undefined, then you apparently don't have the reference for it.  You need to add the appropriate reference. 

    And yes, this is how it works in 2005 and 2008.
    Living my life at 123mph in 11.15 seconds
    Thursday, August 7, 2008 3:53 PM
  • Imports Microsoft.Reporting.WinForms.ReportParameter

    If this is what is needed , it still doesn't work.

    what am I doing wrong?
    Thursday, August 7, 2008 4:56 PM
  •  Imports Microsoft.Reporting.WinForms


    hack off the report parameter part
    Living my life at 123mph in 11.15 seconds
    Thursday, August 7, 2008 4:58 PM
  • there are no errors left.
    thanx a lot...

    My reportviewer looks like this:


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

            Dim reportParam As New reportparameter("param", TextBox1.Text)
            ReportViewer1.LocalReport.SetParameters(New reportparameter() {reportParam})
            TextBox1.Text = "sdcsdcsdc"
            ReportViewer1.Refresh()
        End Sub

    On the report i put a textbox, 

     =Parameters!param.Value
    ,in it.
    And it still doesn't work.

    I'm getting crazy...
    Thursday, August 7, 2008 5:09 PM
  • And how could i be so stupiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiid.

    Thanx everything
     I got it
    Thursday, August 7, 2008 5:12 PM