?
Solved

Passing a Parameter to a Report in ReportViewer

Posted on 2009-07-08
4
Medium Priority
?
718 Views
Last Modified: 2012-05-07
Hi, I'm using VB 2005, WinForms. I have a ReportViewer on one of my Forms which allows me to print a list of items from my DataTable. Currently, I'm getting a list of ALL my items in that DataTable. However, I need to pass a parameter to only show one type of item. In my case it would be the item with ProductID = 67. This parameter will change depending on what the user wants to view.

I can easily do this in a DataGridView by using BindingSource.Filter, but I don't know how to do it in a report in ReportViewer. Can someone explain how parameters are passed to a report "programmatically." By that I mean, I need to pass the variable to the report (in this case 67 as the ProductID) via code and the report should show only those items that are of that product ID type.

I know how to use parameters using the Wizard, but that creates a static report, which does not interact with the users.

In the code snippet below is the code I'm using to generate the report.

Thanks,
Fulano

Dim dtReport As DataTable = DirectCast(reportBS.DataSource, System.Data.DataTable)
Dim frm As New frmSelectedProduct
frm.ReportViewer1.Reset()
frm.ReportViewer1.LocalReport.ReportPath = "../../SelectedProductReport.rdlc"
frm.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_DataTable1", dtReport))
frm.ShowDialog()

Open in new window

0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Accepted Solution

by:
Deathrace earned 2000 total points
ID: 24811729
0
 

Author Comment

by:Mr_Fulano
ID: 24818749
Hi Deathrace, I reviewed your sites, and they did add some value, but I'm not there yet. I still haven't figured out how to pass a parameter to my reports. Your links did help me with the reports themselves, but I'm still stuck on the parameter issue, which is a huge problem for what I need to do.

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24820613
Hi Deathrace,  (interesting name...)

I figured it out...its not straight forward by far, if this is the first time you do this and its definitely VERY poorly documented. However, here's the solution for passing a variable or parameter from a Textbox to the report. You can enter any number in your productsID list and get a report of only that product.

You also have to add a Parameter into your report from the Reports menu option and you have to set a Filter in your report to that parameter.

Thanks for your help!
Fulano
Dim frm As New Form2
Dim parameter As Microsoft.Reporting.WinForms.ReportParameter() = New Microsoft.Reporting.WinForms.ReportParameter(0) {}
parameter(0) = New Microsoft.Reporting.WinForms.ReportParameter("ProductID", Me.TextBox1.Text)
frm.ReportViewer1.LocalReport.SetParameters(parameter)
frm.ShowDialog()

Open in new window

0
 

Author Closing Comment

by:Mr_Fulano
ID: 31601354
Your links helped.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question