SIGN UP MEMBER LOGIN:    
ARTICLE

How do I Pass the Required Parameters of a Stored Procedure in Crystal Reports?

Posted by Jorge L Fernandez Articles | How do I December 30, 2005
This small tip shows how to pass the required parameters of a Stored Procedure in Crystal Reports.
Reader Level:

In many of our applications, we need to generate a report using Crystal Report(CR) to retrieve data into a certain format. The report can have as data source a XML Document, a DataSet, a Table or even a Stored Procedure from a database. This article describes how to pass the required parameters of a Stored Procedure that is being used as data source by a CR report. If these parameters are not passed through code when loading the report viewer (crystalReportViewer class), a dialog will be shown requesting each necessary parameter for execute the Store Procedure.

If we want, we can avoid this dialog and dynamically enter all the parameters in the code.

The fallowing C# code avoid that:

//
// We need declare this namespace
//
using CrystalDecisions.Shared;

The code of below needs to be written after the ReportSource porperty of the crystalReportViewer has been  set and before the control to which belongs finishes being loaded.In this case, we are adding two parameters

ParameterField field1 = this.crystalReportViewer1.ParameterFieldInfo[0];
ParameterField field2 =
this.crystalReportViewer1.ParameterFieldInfo[1];
ParameterDiscreteValue val1 =
new ParameterDiscreteValue();
ParameterDiscreteValue val2 =
new ParameterDiscreteValue();
val1.Value = "parameter1";
val2.Value = "parameter2";
field1.CurrentValues.Add(val1);
field2.CurrentValues.Add(val2);

That's all we need to do.

Login to add your contents and source code to this article
share this article :
post comment
 

please help me..

Posted by suraj repe Jan 16, 2012

please help me..

Posted by suraj repe Jan 16, 2012

i use combo box in form i want to display all field in report when i select index in combo box

Posted by suraj repe Jan 16, 2012

doesn't work for me...

Posted by Iulia Duciuc Jun 09, 2011

i have an error load report failed. plz help me code is :- private void btnok_Click(object sender, EventArgs e) { CryRepViewSumm.ReportSource = @"D:\DDM\CertificateProj\CertificateProj\CryRepSumm.rpt"; ParameterField field1 = this.CryRepViewSumm.ParameterFieldInfo[0]; ParameterField field2 = this.CryRepViewSumm.ParameterFieldInfo[1]; ParameterDiscreteValue val1 = new ParameterDiscreteValue(); ParameterDiscreteValue val2 = new ParameterDiscreteValue(); val1.Value = dtpfrom.Text; val2.Value = dtpto.Text; field1.CurrentValues.Add(val1); field2.CurrentValues.Add(val2); }

Posted by ajay verma Jun 15, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor