Using parameters in Local Mode

Hello there. I am using Visual studio 2005 and am trying to create a report with parameters. The report gets the data from a access 2003 database. Basically what happens is I have a reportviewer on my form. After the report runs, I have a textbox where a person can enter a date.

When I run the project I get an error in my code that says "InvalidCastException was unhandled. Unable to cast object of type 'microsoft.winforms.reportparameter' to type 'system.collections.generic.ienumericable `1 [Microsoft.reporting.winforms.reportparameter]'. Here is my code Below on the button click"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim parameters As ReportParameter

Dim para As DateTime = TextBox1.Text

parameters = New ReportParameter("Dated", para)

Me.ReportViewer1.LocalReport.SetParameters(parameters)

ReportViewer1.RefreshReport()

End Sub

"Dated" is the Parameter that I call in my report. when I look at "Parameters" in the me.reportviewer1.localreport... it comes up as "Dated"

Any suggestions Thanks nick



Answer this question

Using parameters in Local Mode

  • Babu Krisnaswamy-MSFT

    Can you give me an example of an array of reportParameter I am pretty lost here. Thanks!
  • SaravananK

    Dim parameters As ReportParameter

    Dim para As DateTime = TextBox1.Text

    parameters = New ReportParameter("Dated", para)

    Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {parameters})

    ReportViewer1.RefreshReport()

    This is the code that I am using now. It works perfectly.


  • Haowell

    SetParameters take an object that implements IEnumerable, such as an array. You need to pass in an array of ReportParameter objects.
  • Using parameters in Local Mode