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.

suraj repePosted Jan 16, 2012, 3:35 AM
i use combo box in form i want to display all field in report when i select index in combo box
Iulia DuciucPosted Jun 9, 2011, 3:44 PM
doesn't work for me...
ajay vermaPosted Jun 15, 2010, 3:05 AM
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); }
Bill AlveyPosted Oct 13, 2008, 6:16 PM
When I would run my code, the paramater list would pop up as soon as the form loaded. Putting your code in the Form_Load method kept that from happening - which is great!, but then after populating the parameter text boxes on the form, when I click the print report button, which initiates this.crystalReportViewer1.RefreshReport();, the parameter pop-up asks for the parameters anyway. So, your code, got me half way there - which is definitely an improvement! Thanks.
vegaiah kodamgundlaPosted Mar 5, 2008, 1:54 AM
Hai Sir.. How to pass the parameters to the crystal Reports in C#.NET and filter the values programatically as datewise or record numberwise.? Please help sir...... Thank you sir..........
Dotun GbilePosted Nov 16, 2007, 12:55 PM
Here is my code. I am using just one parameter but this is not working. is there something else I need to do? private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ParameterField field1 = this.CrystalReportViewer1.ParameterFieldInfo[0]; ParameterDiscreteValue val1 = new ParameterDiscreteValue(); val1.Value = 191748; field1.CurrentValues.Add(val1); } Thanks.
QuinnPosted Jul 26, 2007, 2:09 AM
I'm using VS .Net 2005 built-in crystal report to create a report in C#. Using stored procedure as the data source. Setting the parameters using SetParameterValue(). Parameters are being set well. But when i run the report the message 'Parameter was not supplied' pops up. Can u please help on this? Thanks
QuinnPosted Jul 26, 2007, 1:45 AM
I'm using VS .Net 2005 built-in crystal report to create a report in C#. Using stored procedure as the data source. Setting the parameters using SetParameterValue(). Parameters are being set well. But when i run the report the message 'Parameter was not supplied' pops up. Can u please help on this? Thanks
QuinnPosted Jul 26, 2007, 1:43 AM
I'm using VS .Net 2005 built-in crystal report to create a report in C#. Using stored procedure as the data source. Setting the parameters using SetParameterValue(). Parameters are being set well. But when i run the report the message 'Parameter was not supplied' pops up. Can u please help on this? Thanks
mohammed alkaffPosted Nov 1, 2006, 12:55 AM
Hello How Can I Passe The Parameter of .Net To crystalReport that Use The Store Procedure, The StoreProcedure has Parameters And Take Values Of TextBoxes In Form thanks
mohammed alkaffPosted Nov 1, 2006, 12:52 AM
Hello How Can I Passe The Parameter of .Net To crystalReport that Use The Store Procedure, The StoreProcedure has Parameters thanks
Ashok KumareditedPosted Jul 4, 2006, 1:16 PMEdited Jan 2, 2007, 10:34 PM
Hi, I am using vb.net and crystal report . I want to pass one text (say company na to report (not through any database field) Could you please tell me how it is possible Thank you Ashok G
Joshua NaheditedPosted Feb 12, 2006, 10:42 PMEdited Oct 7, 2006, 6:37 AM
If found this way to enter parameters of stored procedures into reports better: // Put user code to initialize the page here (Page_Load method - Web Form) //I created Crystal Report named OrdersReport to display shopping cart orders OrdersReport orpt=new OrdersReport(); //The Value needs to be wrapped by a ParameterDiscreteValue ParameterDiscreteValue valOrderID=new ParameterDiscreteValue(); //I got the value from a query string //Get OrderID int OrderID=Int32.Parse(Request.Params["OrderaID"].ToString()); //Set Parameter Value for OrderID valOrderID.Value=OrderID.ToString(); //Set OrdersReport Variable Values orpt.SetParameterValue("@OrderID",valOrderID); //I had a subreport to display other costs to deliver items to the customer. //The subreport also used a stored procedure //The subreport was named OrdersTotalEverything //You can pass in the value for that subreport as such: orpt.SetParameterValue("@OrderID",valOrderID,"OrdersTotalEverything"); //Set Crystal Report Viewer. My Crystal Report Viewer ID was CRV CRV.ReportSource=orpt; CRV.Visible=true;
mounil keditedPosted Jan 16, 2006, 11:15 PMEdited Jan 16, 2006, 11:39 PM
Hi, I developed my app in VS 2003 and it was all running very smoothly. I recently migrated it to VS2005 and then I started getting this problem. Although I dont think this is a VS 2005 issue; but something with CR itself. I'll try to explain my problem in detail. I am using Crystal Reports XI; VS 2005; SQL Server 2000; For all my reports, the reports' datasource is a Stored Procedure. And in most cases than not, these are paramaterised SP's. In my application, I have a listbox with a list of available reports. The user then selects to view one report. This then loads up a dynamically generated form with a tabpage for each of the parameters that the Stored Procedure needs. The user then enters values for each of the parameters. I then create a SQL statement( something like ...execute MyStoredProc value1 value2) where value1 etc are the values the user entered for the parameters on the dynamyically generated form. The resultant recordset is then stored into a DataSet object. I then load the report into a ReportDocument object ie rdReport.Load("ReportLocation"); assign the DataSet as the ReportDocuments' Datasource ie rdReport.SetDataSource(dtsReportData); and finally assign the ReportDocument to the CrystalReportViewer. As i mentioned earlier, this was all working smoothly untill now...I am getting the default CR "Enter Parameters" dialog and I havent got a clue as to what has triggered this behaviour. It is not possible for me to know how many parameters a stored procedure for a report will contain and what those parameters will be for reports designed in the future for the client I am pretty new to the world of reporting so excuse my explanation....if you need any further information to understand my problem, please let me know. I will really appreciate any help that you can provide. Thanks, Mounil.