Author Topic: VB.NET ReportViewer Parameters problem  (Read 6301 times)

Touti

  • Guest
VB.NET ReportViewer Parameters problem
« on: January 15, 2008, 05:15:33 PM »
I know we have a few programmers here so I thought maybe one of you could help with this.

Dim P(1) As ReportParameter
P(0) = New ReportParameter("Customer", TextBox1.Text.Trim, True)
P(1) = New ReportParameter("Style", TextBox2.Text.Trim, True)
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {P(0), P(1)})

I can't figure out why I'm getting

Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter[]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'

on execution of line 4.  I tried every variance of that code I could think of for building the parameters array but it just doesn't work.

Offline DJ Doena

  • Administrator
  • Mega Heavy Poster
  • *****
  • Posts: 6706
  • Country: de
  • Battle Troll
    • View Profile
    • My Blog
Re: VB.NET ReportViewer Parameters problem
« Reply #1 on: January 15, 2008, 05:37:04 PM »
VB.NET long time no see.

you declare an array of ReportParameter with two values. And when you call SetParameters you create a new array just to copy both elements into it. Why?

But your problem is this:

Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter[]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'

Wrong class in the wrong namespace

After correcting this you should call

ReportViewer1.LocalReport.SetParameters(P)
« Last Edit: January 15, 2008, 05:38:42 PM by DJ Doena »
Karsten

Abraham Lincoln once said The trouble with quotes from the internet is that you never know if they're genuine.

my Blog | my DVD Profiler Tools


Touti

  • Guest
Re: VB.NET ReportViewer Parameters problem
« Reply #2 on: January 15, 2008, 07:23:05 PM »
VB.NET long time no see.

you declare an array of ReportParameter with two values. And when you call SetParameters you create a new array just to copy both elements into it. Why?

That's not how I had it in the first place, it just happenS to be the last example I tried from my research on msdn forums.

Quote
But your problem is this:

Unable to cast object of type 'Microsoft.Reporting.WebForms.ReportParameter[]' to type 'System.Collections.Generic.IEnumerable`1[Microsoft.Reporting.WinForms.ReportParameter]'

Wrong class in the wrong namespace

After correcting this you should call

ReportViewer1.LocalReport.SetParameters(P)

Yes I know, I found it before lunch but thanks anyway.
« Last Edit: January 15, 2008, 07:33:59 PM by Touti »