I've got an .RDLC report in an ASP.NET website that I render in a ReportViewer control. The RDLC report is included in teh project, i.e. it is not a SQL Report Server report. It runs fine, i.e. renders data. However, my problem is how to set the value
of the parameters on the report. I've tried the following, but I got an error on the .SetParameters line. And I'm not sure this is the correct approach since the documentation says .SetParameter is only for SQL Report Server reports.
Dim oParams As
New List(Of WebForms.ReportParameter)
From your description, it seems that you want to pass value into your rdlc report, right?
Generally, you can use ReportParameter to feed the parameters to your report. See the following code:
int ParaId = 5;
ReportParameter[] params = new ReportParameter[1];
params[0] = new ReportParameter("ParaId", ParaId, false);
this.ReportViewer1.ServerReport.SetParameters(params);
this.ReportViewer1.ServerReport.Refresh();
And after you've added the code, you also need to define the parameter in the .rdlc file as well. With the .rdlc file open in Visual Studio, go to the Report menu and select Report Parameters.
To be consistent with the code, you should add a parameter named ParaId and then click OK to close the window.
Finally in your .rdlc report designer, you should add a textbox and use expression editor (right-click the textbox and select expression) to set its value =Parameters! ParaId.Value
I am sure by now we all know that that bit of code is insufficient to run an rdlc with parameters coming from visual basic.net
I have done many things including scouring the internet for solutions and it still fails.
This what I have done:
Firstly in vb.net
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
Dim SelectionRange As String
Try
If Trim(ComboBox1.Text = "") Then
Else
SelectionRange = Trim(ChequeDateDateTimePicker.Text & " To " & DateTimePicker1.Text)
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("SelectionRange", SelectionRange, False)
Me.ReportViewer1.RefreshReport()
Me.ReportViewer1.LocalReport.SetParameters(params)
End If
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
Then in Reports Menu
Set Report Parameter to SelectionRange of Type String
then made it internal values
accept blanks and default value as 'Not Limited'
Then in the RDLC File; the Report Definition
I added a text box to the report and right clicked on it to see additional options.
I selected the Expression and a form popped-up
I then selected parameters->All parameters-> SelectionRange and that parameter was pated to the function box.
You have to type = before it and it will look like this:
I am having a similiar issue with these .rdlc report parameters. How do I get them to appear? Granted I can have a dropdownlist with parameters and implement all sorts of logic to show and hide fields to enter a date range in, but I should be able to see
these values before I click "RUN REPORT" button. Here is some of my code, please expand for everyone who has this problems sake.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;
public partial class Reporting_Reporting : System.Web.UI.Page
{
ConnectionString _connectionString = new ConnectionString();
Alerting _alert = new Alerting();
DataTable _dtblParts = new DataTable();
DataSet myDataSet = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
public DataSet GetDataKeys(SqlDataAdapter dad)
{
//GridView _gridView = (GridView)sender;
DataTable dtblPartsRequested = new DataTable();
DataColumn[] keys = new DataColumn[1];
DataSet myDataSet = new DataSet();
dad.Fill(myDataSet);
return myDataSet;
}
protected void btnRunReport_Click(object sender, EventArgs e)
{
ReportViewer1.Visible = true;
using (SqlConnection conn = new SqlConnection(_connectionString.GetConnectionString(1)))
{
SqlDataAdapter dad = new SqlDataAdapter("sp_rpt_MostProblematicItemsV2", conn);
dad.SelectCommand.CommandType = CommandType.StoredProcedure;
myDataSet = GetDataKeys(dad);
ReportDataSource ds = new ReportDataSource("CustomerServiceDataSet_sp_rpt_MostProblematicItemsV2", myDataSet.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.ReportPath = "Reporting/Reports/Report1.rdlc";
ReportViewer1.LocalReport.DataSources.Add(ds);
if (myDataSet.Tables[0].Rows.Count == 0)
{
// no data returned
_alert.HandleAlert(Alerting.AlertType.NotImplemented, Page);
}
// set param values, not really doing anything except showing up in the report,
// after the fact.
string paraStartDate = Convert.ToDateTime("1/1/2009").ToShortDateString();
string paraEndDate = Convert.ToDateTime("12/1/2009").ToShortDateString();
ReportParameter[] param = new ReportParameter[2];
param[0] = new ReportParameter("paraStartDate", paraStartDate, false);
param[1] = new ReportParameter("paraEndDate", paraEndDate, false);
this.ReportViewer1.LocalReport.SetParameters(param);
ReportViewer1.LocalReport.Refresh();
}
}
}
AlexB1318
Participant
1991 Points
468 Posts
Setting Parameter values in an .RDLC report
Nov 01, 2007 08:27 PM|LINK
I've got an .RDLC report in an ASP.NET website that I render in a ReportViewer control. The RDLC report is included in teh project, i.e. it is not a SQL Report Server report. It runs fine, i.e. renders data. However, my problem is how to set the value of the parameters on the report. I've tried the following, but I got an error on the .SetParameters line. And I'm not sure this is the correct approach since the documentation says .SetParameter is only for SQL Report Server reports.
Dim oParams As New List(Of WebForms.ReportParameter)
oParams.Add(New ReportParameter("param1", Now.ToString)).ServerReport.SetParameters(oParams)
I've poured over all of the documentation on Report Services, but I couldn't find anyting on how to set parameter values.
Any ideas anyone?
Thanks, Alex
Nai-Dong Jin...
All-Star
41630 Points
3558 Posts
Re: Setting Parameter values in an .RDLC report
Nov 06, 2007 05:21 AM|LINK
Hi,
From your description, it seems that you want to pass value into your rdlc report, right?
Generally, you can use ReportParameter to feed the parameters to your report. See the following code:
int ParaId = 5;
ReportParameter[] params = new ReportParameter[1];
params[0] = new ReportParameter("ParaId", ParaId, false);
this.ReportViewer1.ServerReport.SetParameters(params);
this.ReportViewer1.ServerReport.Refresh();
And after you've added the code, you also need to define the parameter in the .rdlc file as well. With the .rdlc file open in Visual Studio, go to the Report menu and select Report Parameters.
To be consistent with the code, you should add a parameter named ParaId and then click OK to close the window.
Finally in your .rdlc report designer, you should add a textbox and use expression editor (right-click the textbox and select expression) to set its value =Parameters! ParaId.Value
Thanks.
villegates
Member
2 Points
1 Post
Re: Setting Parameter values in an .RDLC report
Jul 02, 2008 09:47 PM|LINK
I am sure by now we all know that that bit of code is insufficient to run an rdlc with parameters coming from visual basic.net
I have done many things including scouring the internet for solutions and it still fails.
This what I have done:
Firstly in vb.net
Dim params(0) As Microsoft.Reporting.WinForms.ReportParameter
Dim SelectionRange As String
Try
If Trim(ComboBox1.Text = "") Then
Else
SelectionRange = Trim(ChequeDateDateTimePicker.Text & " To " & DateTimePicker1.Text)
params(0) = New Microsoft.Reporting.WinForms.ReportParameter("SelectionRange", SelectionRange, False)
Me.ReportViewer1.RefreshReport()
Me.ReportViewer1.LocalReport.SetParameters(params)
End If
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
Then in Reports Menu
Set Report Parameter to SelectionRange of Type String
then made it internal values
accept blanks and default value as 'Not Limited'
Then in the RDLC File; the Report Definition
I added a text box to the report and right clicked on it to see additional options.
I selected the Expression and a form popped-up
I then selected parameters->All parameters-> SelectionRange and that parameter was pated to the function box.
You have to type = before it and it will look like this:
=Parameters!SelectionRange.Value
And Now
I still got an error when trying to do
:Me.ReportViewer1.LocalReport.SetParameters(params)
ERROR: an error occurred while processing the report
But when I comment out that line I get 'Not Limited'
rdlc Report Viewer rdlc reportviewer data sources mapped namespace rdlc reportviewer program-generated reporting
vellore.bala...
Member
4 Points
15 Posts
Re: Setting Parameter values in an .RDLC report
Dec 07, 2008 08:28 PM|LINK
hi.,
your answer is useful...
can u tell how to set the parameter in the Report.rdlc....
rldc report
working as a Web Developer... in ASP.net Field
Xequence
Contributor
4313 Points
1528 Posts
Re: Setting Parameter values in an .RDLC report
Aug 20, 2009 03:17 AM|LINK
I am having a similiar issue with these .rdlc report parameters. How do I get them to appear? Granted I can have a dropdownlist with parameters and implement all sorts of logic to show and hide fields to enter a date range in, but I should be able to see these values before I click "RUN REPORT" button. Here is some of my code, please expand for everyone who has this problems sake.
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.Reporting.WebForms; public partial class Reporting_Reporting : System.Web.UI.Page { ConnectionString _connectionString = new ConnectionString(); Alerting _alert = new Alerting(); DataTable _dtblParts = new DataTable(); DataSet myDataSet = new DataSet(); protected void Page_Load(object sender, EventArgs e) { } public DataSet GetDataKeys(SqlDataAdapter dad) { //GridView _gridView = (GridView)sender; DataTable dtblPartsRequested = new DataTable(); DataColumn[] keys = new DataColumn[1]; DataSet myDataSet = new DataSet(); dad.Fill(myDataSet); return myDataSet; } protected void btnRunReport_Click(object sender, EventArgs e) { ReportViewer1.Visible = true; using (SqlConnection conn = new SqlConnection(_connectionString.GetConnectionString(1))) { SqlDataAdapter dad = new SqlDataAdapter("sp_rpt_MostProblematicItemsV2", conn); dad.SelectCommand.CommandType = CommandType.StoredProcedure; myDataSet = GetDataKeys(dad); ReportDataSource ds = new ReportDataSource("CustomerServiceDataSet_sp_rpt_MostProblematicItemsV2", myDataSet.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.ReportPath = "Reporting/Reports/Report1.rdlc"; ReportViewer1.LocalReport.DataSources.Add(ds); if (myDataSet.Tables[0].Rows.Count == 0) { // no data returned _alert.HandleAlert(Alerting.AlertType.NotImplemented, Page); } // set param values, not really doing anything except showing up in the report, // after the fact. string paraStartDate = Convert.ToDateTime("1/1/2009").ToShortDateString(); string paraEndDate = Convert.ToDateTime("12/1/2009").ToShortDateString(); ReportParameter[] param = new ReportParameter[2]; param[0] = new ReportParameter("paraStartDate", paraStartDate, false); param[1] = new ReportParameter("paraEndDate", paraEndDate, false); this.ReportViewer1.LocalReport.SetParameters(param); ReportViewer1.LocalReport.Refresh(); } } }<asp:Button ID="btnRunReport" runat="server" Text="Run Report" onclick="btnRunReport_Click" /> <br /> <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Width="600px" ShowParameterPrompts="true" AsyncRendering="false"> </rsweb:ReportViewer>Credentials