Difficulty setting ReportParameter

I am running into issues with setting the ReportParameter method. I am dynamcially setting an ObjectDataSource that is connected to a class object, and dynamically setting a ReportViewer Object. I am running into issues setting the parameters for the report dynamicallly. Here is my code:

publicpartialclassProductReport : System.Web.UI.Page

{

protectedReportViewer reportViewer =newReportViewer();

protectedObjectDataSource objDataSource =newObjectDataSource();

protected System.Web.UI.HtmlControls.HtmlTableCell tdRptViewer =newHtmlTableCell();

protectedvoid Page_Load(object sender,EventArgs e)

{

this.tdRptViewer.ID ="tdRptViewer";

this.form1.Controls.Add(tdRptViewer);

this.tdRptViewer.Focus();

this.form1.Controls.Add(reportViewer);

this.Form.Controls.Add(objDataSource);

this.reportViewer.ProcessingMode =ProcessingMode.Local;

this.reportViewer.LocalReport.DisplayName ="ShippedProduct.rdlc";

this.reportViewer.LocalReport.ReportPath ="ShippedProduct.rdlc";

//this.objDataSource = new ObjectDataSource("objDataSource", "GetProductShipped");

this.objDataSource.ID ="objDataSource";

this.objDataSource.SelectMethod ="GetProductShipped";

this.objDataSource.TypeName ="Intel.JecortezSrv.DataLayer.ShippedProducts";

this.objDataSource.SelectParameters.Add("spName",TypeCode.String,"ProductShipped");

this.objDataSource.SelectParameters.Add("spParam",TypeCode.String,"@parameter1");

this.objDataSource.SelectParameters.Add("spParamValues",TypeCode.String,"test");

this.objDataSource.EnableViewState =true;

this.objDataSource.Select();

this.objDataSource.DataBind();

this.reportViewer.LocalReport.DataSources.Add(newReportDataSource("GetProductShipped", objDataSource.ID));

this.reportViewer.LocalReport.SetParameters(newReportParameter("spName","ProductShipped",false));

this.reportViewer.LocalReport.SetParameters(newReportParameter("spParam","@parameter1",false));

this.reportViewer.LocalReport.SetParameters(newReportParameter("spParamValues","test",false));

this.reportViewer.LocalReport.Refresh();

}
-

The "this.reportViewer.LocalReport.SetParameters(new ReportParameter(parm, parm, parm))" lines are returning the following error:

>>>Error 1 c:\Documents and Settings\jecortez.amr.000\My Documents\Visual Studio 2005\WebSites\SSRSWebConsole\ProductReport.aspx.cs(41): error CS1502: The best overloaded method match for 'Microsoft.Reporting.WebForms.Report.SetParameters(Microsoft.Reporting.WebForms.ReportParameter[])' has some invalid arguments<<<

What is the issue here? Thanks

[7522 byte] By [Paytheon] at [2007-12-16]
# 1
The method is expecting an array of parameters and you are giving it a single parameter. Try something like this instead:

ReportParameter[] params = new ReportParameter[3];
params[0] = new ReportParameter("spName", "ProductShipped", false);
params[1] = new ReportParameter("spParam", "@parameter1", false);
params[2] = new ReportParameter("spParamValues", "test", false);

this.reportViewer.LocalReport.SetParameters(params);

JamesKovacs at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 2

Thanks. That worked nicely.

Paytheon at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 3
Hi,
Could you please send the sample code.

Regards,
Baskar.D

baskardurai at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 4
Hello,
I am having problems passing multivalue parameter to the report viewer through the .net layer.Please help
JackTruneh at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 5

Which event do you put the code under to get the report filtered? I have it under ReportViewer1_Load, the following runs without error but I still get all values in the report.

Dim params(0) As Microsoft.Reporting.WebForms.ReportParameter

params(0) = New Microsoft.Reporting.WebForms.ReportParameter("ProductID", 47)

ReportViewer1.LocalReport.SetParameters(params)

ReportViewer1.LocalReport.Refresh()

DerekMcLachlan at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 6

Bravissimo, dopo 10 giorni di ricerche ho trovato la soluzione grazie a te.

Thanks

Giovanni

GiovanniGavazzi at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 7

Referencing your code; why would I get a precompile error on the SetParameters (Params) statement and you don't?

Me.ReportViewer2.ProcessingMode = ProcessingMode.Local

Me.ReportViewer2.LocalReport.ReportPath = strReportPath

' Parameters

Dim Params(3) As ReportParameter

Params(0) = New ReportParameter("MainTitle", "New Main Title")

Params(1) = New ReportParameter("X-Axis", "New X Axis")

Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

' Precompile error for Params: Value of type '1-dimensional array of Microsoft.Reporting.WinForms.ReportParameter' cannot be converted to 'String'.

If I change it to 'Params.ToString' the precompile swiggly line goes away but then I get an execution error:

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

Thanks,

Bunk

Bunk at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 8

Referencing your code; why would I get a precompile error on the SetParameters (Params) statement and you don't?

Me.ReportViewer2.ProcessingMode = ProcessingMode.Local

Me.ReportViewer2.LocalReport.ReportPath = strReportPath

' Parameters

Dim Params(3) As ReportParameter

Params(0) = New ReportParameter("MainTitle", "New Main Title")

Params(1) = New ReportParameter("X-Axis", "New X Axis")

Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

' Precompile error for Params: Value of type '1-dimensional array of Microsoft.Reporting.WinForms.ReportParameter' cannot be converted to 'String'.

If I change it to 'Params.ToString' the precompile swiggly line goes away but then I get an execution error:

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

Thanks,

Bunk

Bunk at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 9

I usually work in C#, but I think the change below should fix it:

Dim Params(3) As ReportParameter

Params(0) = New ReportParameter("MainTitle", "New Main Title")

Params(1) = New ReportParameter("X-Axis", "New X Axis")

Params(2) = New ReportParameter("Y-Axis", "New Y Axis")

'Me.ReportViewer2.LocalReport.SetParameters(New ReportParameter(Params))

Me.ReportViewer2.LocalReport.SetParameters(Params)

Hope that helps.

BrucePotter at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 10

Hi Derek,

I have exactly the same problem trying to set a parameter to a local report:

Dim myReportParams(0) As ReportParameter

myReportParams(0) = New ReportParameter("str_rpt_date", "2007/07/01")

Me.ReportViewer1.LocalReport.SetParameters(myReportParams)

Me.ReportViewer1.LocalReport.Refresh()

Any ideas why the myReportParams(0) is not set the value? I can see that the NAME is set correctly thru the debugger though.

Thanks,

KC

kchan9999 at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 11

Hi KC

Try this it actually works..

ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials
ReportViewer1.ServerReport.ReportServerUrl = New Uri(strReportServer)
ReportViewer1.ServerReport.ReportPath = strPATH

Dim paramlist As New Generic.List(Of ReportParameter)

paramlist.Add(New ReportParameter(strParmName1, strParmValue1, False))
paramlist.Add(New ReportParameter(strParmName2, strParmValue2, False))

ReportViewer1.ServerReport.SetParameters(paramlist)


ReportViewer1.ServerReport.Refresh()

Regards,

David

David at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 12

I got an error "Too many arguments to Public Sub New()" on

Code Snippet
ReportViewer1.ServerReport.SetParameters(New ReportParameter("intProjectID", 119))

I also tried this and got error on multiple parameters starting the second parameter. It works on single parameter.

Code Snippet
Dim param(2) As Microsoft.Reporting.WebForms.ReportParameter
param(0) = New Microsoft.Reporting.WebForms.ReportParameter("ProjectID", Me.cboProject.SelectedValue)
param(1) = New Microsoft.Reporting.WebForms.ReportParameter("RunBy", Session("strEmployeeName"))
Me.ReportViewer1.ServerReport.SetParameters(param)

What did I miss? Thanks.

DanYeung

danyeungw at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...

Visual Studio

Site Classified