How to pass Report parameter in ReportViewer Control

Hello Friends,

I am using VS2005. how to pass the Report parameter in the reportviewer control? I am using ther Remote mode for the report.

till now i know that i can set the parameter is using the bellow method. This SetParamters method only accept the parameter like Microsoft.Reporting.WinForms.ReportParameter type.

this.reportViewer1.ServerReport.SetParameters().

But can't findout how to pass that parameter in the method.

please help me.

Nilay

[533 byte] By [Nilay] at [2007-12-24]
# 1

Hi, you can do it like this:

Dim objParameter As ReportParameter

zobjParameter = New ReportParameter(strParamName, strParamValue)

Me.objReportViewer.ServerReport.SetParameters(zstrParameter)
Hope this helps!
Alejandro.

AlejandroGutierrez at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 2
A small correction...

Dim objParameter As ReportParameter

zobjParameter = New ReportParameter(strParamName, strParamValue)

Me.objReportViewer.ServerReport.SetParameters(zobjParameter)

Alejandro.

AlejandroGutierrez at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 4

Hi,

If i try to use the same code, it is showing the following error:

Value of type "ReportParameter" cannot be converted to One-dimensional array.

Any idea/solution.

Thanks in advance.

RamaNagesh at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 5
The VB snippet in the documentation is incorrect. The SetParameters method takes a collection (array, list etc) of ReportParameters, not a single ReportParameter object.
RajeevKarunakaran at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 6

Thanks for reply

I have used like the following.

Microsoft.Reporting.WinForms.ReportParameter rprameter = new Microsoft.Reporting.WinForms.ReportParameter(paraName, paraValue);

this.rvReportViewer.ServerReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] {rprameter});

and wroks fine. Now I need to pass null/Balnk value for the report. I have also set the property in report parameter to accept the Null and Blank value. But through codding it is not working.

Thanks

Nilna

Nilay at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 7

You can do the following:

parameters[0] = new ReportParameter(key,new string[] {null});

MarediaH at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 8
I can't seem to get that to work in VB. Still gives the error 'Paramater cannot be Null'. Any ideas on making that work in VB?
TGF at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 9
could it be because of your report parameter setting in report designer ?
minority80 at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 10

Has anyone figured out how to pass a null value yet? This code:

parameters(0) = New ReportParameter("X", New String(Nothing))

passes and empty string, not a null value.

usp at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 11

Never mind. I figured it out. Just write this:

parameters(0) = New ReportParameter("X")

usp at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 12

I've used SSRS only but now I need to develop a report in a c# application and this is very confusing. There is a "Find" option at the top of the report viewer control, though do not know where this is coded.

How can I just add a drop-down box or something to allow the user to select from a list of values (parameters)?

polymorphicx at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 13
If you have a parameter defined in the report itself, and have the report viewer control set up to display parameters, it is all taken care of for you.
usp at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...
# 14

I ended up populating the comboBox separately and passing the selected value to the report:

private void frmRptPaintSysList_Load(object sender, EventArgs e)
{
populateComboBox();
this.paintsysTableAdapter.Fill(this.usmDataSet_paintsys.paintsys);
this.reportViewerPaintSysList.RefreshReport();
}

private void populateComboBox()
{
OleDbConnection cnn = new OleDbConnection(strCnn);
OleDbDataReader dr = null;
try
{
cboPaintSysReport.Items.Clear();
string sSQL = "SELECT DISTINCT paintsys_code FROM paintsys ORDER BY paintsys_code";
cnn.Open();
OleDbCommand cmd = new OleDbCommand(sSQL, cnn);
dr = cmd.ExecuteReader();
if (dr != null)
{
while (dr.Read())
{
cboPaintSysReport.Items.Add(dr["paintsys_code"]);
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dr != null)
{
dr.Close();
}
cnn.Close();
}
}

private void cboPaintSysReport_SelectedIndexChanged(object sender, EventArgs e)
{
this.paintsysTableAdapter.FillByCode(this.usmDataSet_paintsys.paintsys, cboPaintSysReport.Text);
reportViewerPaintSysList.RefreshReport();
}

polymorphicx at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Report Controls...

Visual Studio

Site Classified