I have a couple of questions regarding parameters using ReportViewer.
1. Parameters for sp
I have a ReportViewer that takes one parameter that it passes to a stored procedure to return a DataTable, but I do not know how to set the value of that parameter when I set ReportViewer.Visible = True.
2. I'm looking for a way to pass parameters directly to a report (these parameters carry custom text to display in the report depending on choices made by users when requesting the report and have nothing to do with the parameter in question 1 that is needed
for the sp).
2. I'm looking for a way to pass parameters directly to a report (these parameters carry custom text to display in the report depending on choices made by users when requesting the report and have nothing to do with the parameter in question 1 that is needed
for the sp).
Yes, We Can do like this also.. be ensure you have added starttime and endtime parameters added in Report File . For adding parameters in report
Menu Report--> Report Parameters.
// To set the parameter values
ReportParameterInfoCollection parms = ReportViewer1.LocalReport.GetParameters();
foreach(ReportParameterInfo parm in parms)
{
SetReportParameters(parm.Name);
}
In Report File you add this in filter by Table Properties -- > Data -- > Filter options Or we can display the starttime and endtime parameters in header sections.
Thanks for your reply. I believe this is useful. I'll find out soon when I get a chance to try it and I'll let you know. The only other question remaining is how to set the parameter in the GetData method of the OjbectDataSource or TableAdapter, not sure
which one has that method. But this is a parameter that is passed to the SP to return a datatable.
I'm trying to use the code you listed earlier in this thread. I keep getting an error, "An error occurred during local report processing.", on the SetParameters line (see the code below).
The visible property of the ReportViewer control is set to False in the VS2005 GUI. No other properties of the control have been set. Also, I have a report called "QM.rdlc" in my project with two parameters (defined in the Reports menu) called "Hdr_QrTitle"
and "Hdr_Program". These parameters are not used for processing data; they are used simply for display within the report. I'm using VB.Net in VS2005. Here's the code (I'm not too sure about the last 2 lines; I never got to that point):
Dim prmQrTitle As
New ReportParameter("Hdr_QuestionnaireTitle", "Questionnaire 1")
Dim prmProgram
As New ReportParameter("Hdr_Program", "Evening")
Dim parameters()
As ReportParameter = {prmQrTitle, prmProgram}
LocalRpt.SetParameters(parameters) <-- BLOWS UP HERE
Dim prmQrTitle As
New ReportParameter("Hdr_QrTitle", "Questionnaire 1")
Dim prmProgram
As New ReportParameter("Hdr_Program", "Evening")
Dim parameters()
As ReportParameter = {prmQrTitle, prmProgram}
LocalRpt.SetParameters(parameters) <-- BLOWS UP HERE
Dim prmQrTitle As
New ReportParameter("Hdr_QrTitle", "Questionnaire 1")
Dim prmProgram
As New ReportParameter("Hdr_Program", "Evening")
Dim parameters()
As ReportParameter = {prmQrTitle, prmProgram}
ReportViewer1.LocalReport.SetParameters(parameters) <-- BLOWS UP HERE
Sasi, if you are still there, I wonder if you'd be willing to help me a bit further. I'm not getting errors anymore with the parameters, but I still can't get the report to render. I'm having trouble with datasources.
My report (SalesReport.rdlc) has two string parameters, Quarter and AgencyType. Here's the code I'm using (I'm not using the Source Code tool in this editor as it keeps resulting in errors):
With ReportViewer1
.Visible = True
.Reset()
.LocalReport.ReportPath = "SalesReport.rdlc"
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
'All RptParam_ variables have been set earlier in the code
Dim prmQrTitle As New ReportParameter("Quarter", RptParam_Qarter)
Dim prmAgencyType As New ReportParameter("AgencyType", RptParam_AgencyType)
Dim parameters() As ReportParameter = {prmQuarter, prmAgencyType}
.LocalReport.SetParameters(parameters)
.DataBind()
.LocalReport.Refresh()
End With
Here are the problems I am experiencing:
If I use the SmartTag of the ReportViewer to create a dataset, it ends up creating a TableAdapter and an ObjectDataSource. I then assign the resulting DataTable to the DataSetName property of the table in the report. When I run this, it goes through the
code without an error, but where the report should be rendered (where the ReportViewer is), I get this error:
A data source instance has not been supplied for the data source 'SalesReport_SalesReportTable'
If I reset (delete the value of) the DataSetName property, I get the same error. If I then open the rdlc in a text error and delete the <DataSets> element and all its contents, I get this error at complile:
Error 1 The table ‘table2’ is in the report body but the report has no data set. Data regions are not allowed in reports without datasets.
So, I'm very confused. If I am going to assign a DataTable dynamically (at runtime), do I still need to have the DataSetName property of the report table assigned to a datatable? I think I do, since how would the report know about the fields otherwise at
design? But how can I get away from this situation in which I get errors if I assign a DataTable and I get errors if I don't. How DO I set things up so that I can assign a report to a ReportViewer and a DataTable to the LocalReport in code?
How DO I set things up so that I can assign a report to a ReportViewer and a DataTable to the LocalReport in code?
DesertDude
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
The dataTable name you are passing not matching with rdlc dataTable name,
DesertDude
A data source instance has not been supplied for the data source 'SalesReport_SalesReportTable'
Change the name in ReportDataSource as "SalesReport_SalesReportTable"
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport_SalesReportTable"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
~Sasi
Please remember to click "Mark as Answer" on this post if it helped you.
Thanks, Sasi. That puzzled me at first, but it makes sense. The controls in the report are expecting a datatable by a certain name, right? Anyway, the report finally appeared in the ReportViewer for the first time, so this is progress. I'm not completely
out of the woods, yet, but hopefully I can now get there from here.
Thanks so much for your help. You have saved me countless hours. I've marked the Answer as you requested.
Member
8 Points
317 Posts
Report Parameters with ReportViewer?
May 05, 2008 07:03 PM|DesertDude|LINK
I have a couple of questions regarding parameters using ReportViewer.
1. Parameters for sp
I have a ReportViewer that takes one parameter that it passes to a stored procedure to return a DataTable, but I do not know how to set the value of that parameter when I set ReportViewer.Visible = True.
2. I'm looking for a way to pass parameters directly to a report (these parameters carry custom text to display in the report depending on choices made by users when requesting the report and have nothing to do with the parameter in question 1 that is needed for the sp).
Thank you.
Participant
951 Points
295 Posts
Re: Report Parameters with ReportViewer?
May 06, 2008 01:26 AM|sasi.k|LINK
Yes, We Can do like this also.. be ensure you have added starttime and endtime parameters added in Report File . For adding parameters in report
Menu Report--> Report Parameters.
// To set the parameter values
ReportParameterInfoCollection parms = ReportViewer1.LocalReport.GetParameters();
foreach(ReportParameterInfo parm in parms)
{
SetReportParameters(parm.Name);
}
private void SetReportParameters(String parameterName)
{
try
{
if(parameterName.ToLower() == "starttime")
{
ReportParameter startTimeParameter = new ReportParameter(parameterName, txtStartDate.Text);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { startTimeParameter });
}
else if(parameterName.ToLower() == "endtime")
{
ReportParameter endTimeParameter = new ReportParameter(parameterName, txtEndDate.Text);
this.ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { endTimeParameter });
}
}
catch (Exception ex)
{
throw ex;
}
}
In Report File you add this in filter by Table Properties -- > Data -- > Filter options Or we can display the starttime and endtime parameters in header sections.
For More detailed informations go thru this links
http://www.gotreportviewer.com/
http://msdn.microsoft.com/en-us/library/aa337432.aspx
Please remember to click "Mark as Answer" on this post if it helped you.
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 07, 2008 06:34 PM|DesertDude|LINK
Thanks for your reply. I believe this is useful. I'll find out soon when I get a chance to try it and I'll let you know. The only other question remaining is how to set the parameter in the GetData method of the OjbectDataSource or TableAdapter, not sure which one has that method. But this is a parameter that is passed to the SP to return a datatable.
Thanks, again.
Participant
951 Points
295 Posts
Re: Report Parameters with ReportViewer?
May 08, 2008 12:54 AM|sasi.k|LINK
Hi,
Have look on this link .
http://msdn.microsoft.com/en-us/library/57hkzhy5.aspx
Please remember to click "Mark as Answer" on this post if it helped you.
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 08, 2008 06:06 PM|DesertDude|LINK
I'm trying to use the code you listed earlier in this thread. I keep getting an error, "An error occurred during local report processing.", on the SetParameters line (see the code below).
The visible property of the ReportViewer control is set to False in the VS2005 GUI. No other properties of the control have been set. Also, I have a report called "QM.rdlc" in my project with two parameters (defined in the Reports menu) called "Hdr_QrTitle" and "Hdr_Program". These parameters are not used for processing data; they are used simply for display within the report. I'm using VB.Net in VS2005. Here's the code (I'm not too sure about the last 2 lines; I never got to that point):
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.ReportPath = "QM.rdlc"
Dim prmQrTitle As New ReportParameter("Hdr_QuestionnaireTitle", "Questionnaire 1")
Dim prmProgram As New ReportParameter("Hdr_Program", "Evening")
Dim parameters() As ReportParameter = {prmQrTitle, prmProgram}
LocalRpt.SetParameters(parameters) <-- BLOWS UP HERE
ReportViewer1.Visible = True
ReportViewer1.Refresh()
Any ideas? Thanks for your help!
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 08, 2008 06:09 PM|DesertDude|LINK
Sorry, there's a typo in the code I sent you (name of the parameter is wrong). Here's the correct code:
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.ReportPath = "QM.rdlc"
Dim prmQrTitle As New ReportParameter("Hdr_QrTitle", "Questionnaire 1")
Dim prmProgram As New ReportParameter("Hdr_Program", "Evening")
Dim parameters() As ReportParameter = {prmQrTitle, prmProgram}
LocalRpt.SetParameters(parameters) <-- BLOWS UP HERE
ReportViewer1.Visible = True
ReportViewer1.Refresh()
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 08, 2008 06:12 PM|DesertDude|LINK
Well, this is embarassing: another typo. OK, here's the real correct code:
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.ReportPath = "QM.rdlc"
Dim prmQrTitle As New ReportParameter("Hdr_QrTitle", "Questionnaire 1")
Dim prmProgram As New ReportParameter("Hdr_Program", "Evening")
Dim parameters() As ReportParameter = {prmQrTitle, prmProgram}
ReportViewer1.LocalReport.SetParameters(parameters) <-- BLOWS UP HERE
ReportViewer1.Visible = True
ReportViewer1.Refresh()
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 09, 2008 05:23 PM|DesertDude|LINK
so, the problem was that I was giving it the wrong path to the report. The code you supplied was the answer. Thank you.
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 12, 2008 02:32 PM|DesertDude|LINK
Sasi, if you are still there, I wonder if you'd be willing to help me a bit further. I'm not getting errors anymore with the parameters, but I still can't get the report to render. I'm having trouble with datasources.
My report (SalesReport.rdlc) has two string parameters, Quarter and AgencyType. Here's the code I'm using (I'm not using the Source Code tool in this editor as it keeps resulting in errors):
With ReportViewer1
.Visible = True
.Reset()
.LocalReport.ReportPath = "SalesReport.rdlc"
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
'All RptParam_ variables have been set earlier in the code
Dim prmQrTitle As New ReportParameter("Quarter", RptParam_Qarter)
Dim prmAgencyType As New ReportParameter("AgencyType", RptParam_AgencyType)
Dim parameters() As ReportParameter = {prmQuarter, prmAgencyType}
.LocalReport.SetParameters(parameters)
.DataBind()
.LocalReport.Refresh()
End With
Here are the problems I am experiencing:
If I use the SmartTag of the ReportViewer to create a dataset, it ends up creating a TableAdapter and an ObjectDataSource. I then assign the resulting DataTable to the DataSetName property of the table in the report. When I run this, it goes through the code without an error, but where the report should be rendered (where the ReportViewer is), I get this error:
A data source instance has not been supplied for the data source 'SalesReport_SalesReportTable'
If I reset (delete the value of) the DataSetName property, I get the same error. If I then open the rdlc in a text error and delete the <DataSets> element and all its contents, I get this error at complile:
Error 1 The table ‘table2’ is in the report body but the report has no data set. Data regions are not allowed in reports without datasets.
So, I'm very confused. If I am going to assign a DataTable dynamically (at runtime), do I still need to have the DataSetName property of the report table assigned to a datatable? I think I do, since how would the report know about the fields otherwise at design? But how can I get away from this situation in which I get errors if I assign a DataTable and I get errors if I don't. How DO I set things up so that I can assign a report to a ReportViewer and a DataTable to the LocalReport in code?
Thank you very much for your help.
Participant
951 Points
295 Posts
Re: Report Parameters with ReportViewer?
May 13, 2008 01:35 AM|sasi.k|LINK
Hi DesertDude,
The dataTable name you are passing not matching with rdlc dataTable name,
Change the name in ReportDataSource as "SalesReport_SalesReportTable"
Dim rdsReport As New ReportDataSource
With rdsReport
.Name = "SalesReport_SalesReportTable"
.Value = dtReport 'Created earlier in the code
End With
.LocalReport.DataSources.Clear()
.LocalReport.DataSources.Add(rdsReport)
Please remember to click "Mark as Answer" on this post if it helped you.
Member
8 Points
317 Posts
Re: Report Parameters with ReportViewer?
May 13, 2008 05:24 PM|DesertDude|LINK
Thanks, Sasi. That puzzled me at first, but it makes sense. The controls in the report are expecting a datatable by a certain name, right? Anyway, the report finally appeared in the ReportViewer for the first time, so this is progress. I'm not completely out of the woods, yet, but hopefully I can now get there from here.
Thanks so much for your help. You have saved me countless hours. I've marked the Answer as you requested.
Member
202 Points
125 Posts
Re: Report Parameters with ReportViewer?
Jun 24, 2013 11:02 AM|UselessChimp|LINK
Thank you for this reply. It has helped me in my project.