• Welcome to DVD Collectors Online.
 

VB.NET ReportViewer Parameters problem

Started by Touti, January 15, 2008, 05:15:33 PM

Previous topic - Next topic

Touti

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.

DJ Doena

#1
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)
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

#2
Quote from: DJ Doena 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?

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.