How to pass value from textbox as a parameter to the SSRS report?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All, Below is original quesion and I did some workaround but stuck at one place:-
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 for ex, 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?
-----Here is the workaround i came up with but 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 2008 R2 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 parameters 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 thats 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.
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small
------code------
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <font face="Consolas" size="2 <font face="Consolas" size="2

</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small private<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small void<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
winform2_Load(<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small object<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
sender, <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small EventArgs<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
e){<font face="Consolas" size="2 <font face="Consolas" size="2
reportViewer1.ShowCredentialPrompts =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small false<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small reportViewer1.ServerReport.ReportServerUrl =
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small new<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small Uri<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small (<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "http://myServerName/ReportServer"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small );<font face="Consolas" size="2 <font face="Consolas" size="2

reportViewer1.ServerReport.ReportPath = <span style="color:#a31515 "
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small http://myReportPath/myReport.rdl http://myReportPath/myReport.rdl "<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ; <font face="Consolas" size="2 <font face="Consolas" size="2


</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small List<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small ReportParameter<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small >
parameters = <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small new<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small List<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small ReportParameter<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small >();<font face="Consolas" size="2 <font face="Consolas" size="2


</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small <span style="font-family:Consolas; color:#008000; font-size:x-small parameters.Add(new ReportParameter("Year",
textBox1.Text)); //here is that line which gives error
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
reportViewer1.ServerReport.SetParameters(parameters);
<font face="Consolas" size="2 <font face="Consolas" size="2
reportViewer1.ProcessingMode =
</font></font><font face="Consolas" size="2

</font>
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small ProcessingMode<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small .Remote;<font face="Consolas" size="2 <font face="Consolas" size="2

reportViewer1.ShowParameterPrompts =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small false<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;<font face="Consolas" size="2 <font face="Consolas" size="2

reportViewer1.ShowPromptAreaButton =
</font></font><font face="Consolas" size="2

</font>

<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small false<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ;

reportViewer1.ServerReport.Refresh();
}




View the full article
 
Back
Top