How to pass value from textbox as a parameter to the SSRS report
Hi All, I have 2 win forms created in VS 2010 (C#) solution. 1st winform has a text box with label "Enter Year(YYYY)" and when user enters 2010, this value should be passed as a parameter to the SSRS report which I am populating it through ReportViewer control on the 2nd win form. i.e., on 1st win form when user enters year (2010) and hits the button "RunReport" it is re-directing to the second win form, which has this ReportViewer control. and i want this value of year (whatever user enters) to be passed to my SSRS 2008 R2 report, which I have created to take @Year as a parameter. Any idea?
February 18th, 2011 6:34pm

Just overload the constructor on the second form and pass the value upon instantiating the form.John Grove - DSS, Senior Software Engineer
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2011 6:40pm

Something as simple as this: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnRunReport_Click(object sender, EventArgs e) { Int32 year; if (Int32.TryParse(textBox1.Text, out year)) { Form2 form2 = new Form2(year); form2.ShowDialog(); } } } } //Form2 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form { private Int32 Year; public Form2(Int32 year) { InitializeComponent(); this.Year = year; } } } John Grove - DSS, Senior Software Engineer
February 18th, 2011 6:45pm

also it should hide the parameter prompt(Year:) on the SSRS report while we run the application, since we are already passing it programmatically from the textbox to the report within ReportViewer. Currently, when i run the application , i enter Year value on 1st win form and hits "RunReport" button, what it does is it is populating report from R2 report server as it is so when the report is displayed I have to enter Year value there, which I dont want to enter Year value again. in short, it should hide Year prompt for the report when it runs.
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2011 7:13pm

Hi John, I also heard about URL access parameters, can we use that here? because again I will have to create one more win form between Form 1 and Form 2, and this new win form will have another parameter called @Region and I will also need to pass that parameter as well along with @Year, to the SSRS report. So my application flow will look like below:- WinForm1: Textbox (Year) , and button "Next" , which will re-direct to below WinForm2: which has checkedListBox (i.e. multiple select for the Region) and button "RunReport", which will finally re-direct to below WinForm3: which has one reportviewer control, that will display the report from R2 server; and this report should be fetching values of the parameters from WinForm1(@Year) and WinForm2(@Region), and it should display report accordingly making sure user don't have to enter values again for the Year and Region prompts. Hope the question is clear.
February 18th, 2011 7:23pm

Maybe someone else can help you with the specifics of the ReportViewer control as I am not privy with it. But passing information from one form to another is rather straight forward.John Grove - DSS, Senior Software Engineer
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2011 7:32pm

Hi All, Relevant to my question here, I think I have found out some workaround for the same but I am stuck at one place. As my original post says I needed to pass value of Textbox(Year) whatever user enters (from winform1) to my SSRS report which is there in seperate winform2(with ReportViewer control). Now I wrote below piece of code for the LOAD event of the winform2(which contains ReportViewer) My question is : as the below code has one line (in bold) where I try to enter parameter's value from the TextBox1, it gives error saying:- "Error 1 The name 'textBox1' does not exist in the current context " Because it is trying to access the TextBox1 which is present in winform1; so that's why it is giving this error. now I want to know how can I make that textbox value accessible to this winform2 ' s code so that it can recognize it. Please help. ------code------ private void winform2_Load(object sender, EventArgs e) { reportViewer1.ShowCredentialPrompts = false; reportViewer1.ServerReport.ReportServerUrl = new Uri("http://myServerName/ReportServer"); reportViewer1.ServerReport.ReportPath = " http://myReportPath/myReport.rdl"; List<ReportParameter> parameters = new List<ReportParameter>(); parameters.Add(new ReportParameter("Year", textBox1.Text)); reportViewer1.ServerReport.SetParameters(parameters); reportViewer1.ProcessingMode = ProcessingMode.Remote; reportViewer1.ShowParameterPrompts = false; reportViewer1.ShowPromptAreaButton = false; reportViewer1.ServerReport.Refresh(); }
February 22nd, 2011 3:10pm

Hi, Based on discussion above, I noticed that you currently can pass parameter to the server report in a single WinForm. However, you need users to set parameter int one form and display the report by using the ReportViewer in another form. So, in order to achieve this, I would suggest you refer to the walkthrough Passing Data Between Windows Forms at: http://msdn.microsoft.com/en-us/library/ms171925.aspx For more information about use the ReportViewer.ServerReport.SetParameters method sets report parameters for the server report. please refer to: http://msdn.microsoft.com/en-us/library/ms252663(v=VS.100).aspx Thanks, Tony ChainTony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2011 2:22am

Hi, Based on discussion above, I noticed that you currently can pass parameter to the server report in a single WinForm. However, you need users to set parameter int one form and display the report by using the ReportViewer in another form. So, in order to achieve this, I would suggest you refer to the walkthrough Passing Data Between Windows Forms at: http://msdn.microsoft.com/en-us/library/ms171925.aspx For more information about use the ReportViewer.ServerReport.SetParameters method sets report parameters for the server report. please refer to: http://msdn.microsoft.com/en-us/library/ms252663(v=VS.100).aspx Thanks, Tony ChainTony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
February 26th, 2011 2:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics