Creating Parameter Fields in Crystal Reports
page 1 of 3
Published: 27 Apr 2009
Abstract
In this article Mohammad Azam demonstrates the usage of ParameterField in Crystal Reports to manipulate reports at runtime. He examines the concept in a step-by-step manner with a comprehensive explanation and supporting screen shots.
by Mohammad Azam
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 67405/ 198
Article Contents:

Introduction

There are multiple ways of passing parameters to the crystal report. The simplest one is to use the crystal report design time feature to add the parameter manually. This article focuses on the design time approach to attach parameters.

Passing Parameters to Crystal Report Using Designer

This approach involves no coding at all. You will add the parameters using the Crystal Report designer. Let us see step-by-step how to accomplish this task. First, add a new crystal report to the project and name it "ProductsByCategoryReport.rpt." As soon as the report is added, the following dialog box appears on the screen.

Figure 1: Creating a new report

Select "Standard" and click on the "OK" button. The next screen will allow you to select the data source. In the screenshot below we have selected SQL SERVER and selected the "Categories" table and the "Products" table from the Northwind database.

Figure 2: Selecting the Tables

After selecting the tables select the "Next" button. The next screen shows the relationship between the Categories and Products table.

Figure 3: The Table Relationship Screen

 

The CategoryID has a one-to-many relationship with the Products table. This is because of the fact that a single category can contain multiple products.

Click the next button to move forward through the wizard.

Figure 4: Selecting the Fields

The above screen shows the fields available for selection. You can select any fields you want to display on the report.

We have selected several fields from the Products table as shown below in the screenshot.

Figure 5: Fields to Display Screen

Press "Next" to continue. The next screen shows the "Grouping" options for the report. This is useful when your report is presented in groups. A simple group example can be to list the total number of products in each category. Since, we are not using any grouping for this article we will not add any fields.

Figure 6: Grouping Screen

Click "Next" to continue.

The next screen is the record selection screen. We will also by-pass this screen by pressing the next button.

Figure 7: Record Selection Screen

The final screen is the layout screen. The layout screen enables the developer to select a layout for the report. Choose any layout you want and then press the "Finish" button.

Figure 8: Layout Selection Screen

As soon as you press the "Finish" button a prototype of the layout is created and displayed to you as shown in the screenshot below.

Figure 9: Report Prototype Displayed

Now, let us add a page which will display the crystal report.

Displaying Crystal Report on Page

ASP.NET includes a CrystalReportViewer control which enables us to display the crystal report on a web page. First, add a CrystalReportViewer on the page. The CrystalReportViewer needs a CrystalReportSource control. Create a new CrystalReportSource control and point it to the crystal report that you just created. Now, when you run the page, you will see the following output:

Figure 10: Report Displayed in the Browser

The report simply displayed all the records in the Products table. This is because we have not yet configured the "Select Expression" and the "Report Parameters." Let us add a parameter to the report. Go to the report, right click and select "Field Explorer." This will load the field explorer tab where you can add a parameter to the report.

Figure 11: Opening the Field Explorer Window

Now, right click on the Parameter Fields and add a new parameter as shown in the screenshot below.

Figure 12: Adding a Field Parameter

You can drag and drop the parameter field onto the crystal report if you would like to display the parameter field in the report. For this article we will not display the parameter field in the report.

The next step is to add a "Record Selection Formula." The record selection formula option is found under the "Special Fields" option. Right click on the record selection formula and add it to the report. Next, right click on the record selection formula you just added to the report and click on "Select Expert."

Select "CategoryName" as shown in the screenshot below.

Figure 13: Choosing a Field to Match Against the Parameter Field

 

Select the "OK" button.

The next screen shows the filter criteria. We are matching the CategoryName parameter field with the CategoryName in the Categories table.

Figure 14: Creating the Filter Criteria

Select the "OK" button to close the Select Expert window.

Now, run the application again and you will notice that the page prompts you to enter the parameter field, which in this case is the CategoryName.

Figure 15: Enter Parameter Field Value Screen

When the "Submit" button is clicked you will see the results filtered out by the CategoryName.

Figure 16: Filtered Crystal Report Displayed in Browser


View Entire Article

User Comments

Title: VB.net   
Name: Gaurav Upadhyay
Date: 12/26/2012 11:58:53 PM
Comment:
It's good and it provided very helpful information to me..

thanks...
Title: NIKE NFL jerseys   
Name: NIKE NFL jerseys
Date: 7/2/2012 10:09:44 AM
Comment:
http://www.jersey2shop.com
http://www.cheapjersey2store.com
http://www.jerseycaptain.com
http://www.yourjerseyhome.com
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes
Cheap NFL,NBA,MLB,NHL
,heap jerseys,2012 nike nfl Jerseys,nba jersey and shorts,oklahoma city thunder jersey,official jeremy lin new york knicks jersey,NFL Jerseys Wholesale,blake griffin jersey blue,NFL jerseys For Sale online.All Our Jerseys Are Sewn On and Directly From Chinese Jerseys Factory
,Wholesale cheap jerseys,Cheap mlb jerseys,]Nike NFL Jerseys,Cheap China Wholesae,Wholesale jerseys From China,2012 nike nfl Jerseys,Jerseys From China,,2012 nike nfl Jerseys,Revolution 30 nba jerseys,jersey of nba chicago bulls direk rose ,nfl jerseys,green bay packers jerseys wholesale,Buffalo Bills nike nfl jerseys sale,good supplier soccer jerseys,cool base mlb jerseys,Revolution 30 nba jerseys,2012 stanley cup nhl jersey,
We are professional jerseys manufacturer from china,wholesal.cheap nike nfl jerseys, mlb jerseys, nhl jerseys,nba jerseys and shoes. www.yourjerseyhome.com
Title: Creating Parameter Fields in Crystal Reports   
Name: Mohammad Azam
Date: 6/11/2012 4:21:58 PM
Comment:
I am unable to view screenshorts
Title: asd   
Name: asdf
Date: 5/4/2012 3:25:54 AM
Comment:
sadf
Title: Very good   
Name: Sumit Kumar
Date: 9/28/2011 3:38:41 AM
Comment:
Yaar it's a very good stuff. Written in details....thanx..
Title: GOOD   
Name: Koigny Hermann
Date: 7/8/2011 6:05:57 AM
Comment:
Good Stuff. It has really helpt me. Thank You
Title: Wonder full Jan   
Name: Aqeel
Date: 6/18/2011 5:50:43 AM
Comment:
Goooooooooooooood yar u have solved my problum
Title: Excellent   
Name: xyz
Date: 5/16/2011 5:50:10 AM
Comment:
very well written and explained.Thanks.
Title: That's Greate   
Name: Son
Date: 4/8/2011 7:23:18 AM
Comment:
This is great but i need to know how to do the same for a windows form application....is it the same process?....i want it to search the database and display just a row from the database not all....can u help?
Title: Thank u but   
Name: rahul upadhyay
Date: 3/23/2011 7:27:12 AM
Comment:
Ti's nice but i want to pass parameter in run time not ask me after execution.

i want to give the parameter value in run time.
Title: Thank u   
Name: Anj
Date: 2/24/2011 10:04:49 AM
Comment:
Hey , this helped a lot. Thank u very much
Title: very good article   
Name: Rohidas
Date: 2/7/2011 3:58:39 AM
Comment:
This really helped me better under stand Crystal Reports! Thanks!
Title: Nice   
Name: Chanti
Date: 12/24/2010 2:32:00 AM
Comment:
hi yar but i want some examples can u send me to my mailid chanti_7s@yahoo.com.
i want examples on crystal report 2008
Title: very nice   
Name: Noor
Date: 12/19/2010 12:36:19 PM
Comment:
Very nice article step by step easy to understand
thanks
Title: Very Helful Article   
Name: TechToUse
Date: 12/17/2010 6:15:08 AM
Comment:
This is it! I was searching for this kind of article where i can get one stop help for Crystal Reports. Thank you very much
Title: very good article   
Name: gredion
Date: 12/3/2010 12:38:13 AM
Comment:
thank you this is very good article
my problem solved :D
Title: Very Helpful   
Name: Bob
Date: 11/29/2010 5:46:17 PM
Comment:
Well written. Thanks
Title: Very good   
Name: John
Date: 11/24/2010 5:54:57 AM
Comment:
Very very useful artical...
Title: very good   
Name: ahmed
Date: 11/10/2010 7:51:24 AM
Comment:
reaaly very usefull artical
Title: Good   
Name: eng
Date: 11/4/2010 4:09:43 PM
Comment:
This is a good article , it is much usefull to us
Title: Parameter sequence   
Name: san
Date: 9/29/2010 6:20:28 AM
Comment:
does anybody know how to change sequence of parameters.
Title: crystal report   
Name: bis
Date: 9/6/2010 5:15:04 AM
Comment:
very best explanation
Title: Good One   
Name: Firojul Islam
Date: 9/2/2010 5:49:59 PM
Comment:
explanation and illustration is very good.

can you tell me which crystal report version has been used here ?
Title: Nice   
Name: Kumar
Date: 8/24/2010 11:55:03 PM
Comment:
This is a good article , it is much usefull to us
Title: Nice   
Name: Alicia
Date: 7/16/2010 10:30:58 AM
Comment:
This is a good article, I wish it showed how to make split paramaters work, I have a project that is causing a ton of stress.
Title: Crystal Report Parameter   
Name: Haresh Jaiswal
Date: 7/3/2010 11:25:09 PM
Comment:
Wow... very nice article Mohd. Azam... its really helpful
Title: Crystal report parameter   
Name: Ritesh Patil
Date: 7/2/2010 11:29:44 PM
Comment:
Really helpfull article for novice.... Thanks a lot bro...
Title: thanks   
Name: waseem
Date: 5/22/2010 6:30:09 AM
Comment:
thanks
Title: Thank   
Name: Ammar Ramadan
Date: 5/18/2010 4:43:47 AM
Comment:
Thank you Mr.Mohammad ,,this useful method and it's help me
regards
Title: Mr   
Name: Ahmad Hussain
Date: 5/16/2010 5:41:31 AM
Comment:
Dear Mohammad Jazak Allah O khair , thx lot , this article helped me lot to solve my problem. I entitle you Mr 5 star.
Thx lot
Title: creating paremeter fields   
Name: ken mulinge
Date: 4/16/2010 9:09:08 AM
Comment:
very helpful
Title: how to enter parameter fields in crystal reports   
Name: Amila Ranasinghe
Date: 3/18/2010 5:56:25 AM
Comment:
Very useful article, i got my question resolved by reading this.

thanks
Title: Creating Parameter   
Name: Aby Thomas
Date: 3/2/2010 1:48:04 AM
Comment:
Its Excellent Work.really good.

Thanks for your smart work.
Title: Creating Parameter fields in Crystal Reports   
Name: M.Krishnapriya
Date: 1/20/2010 11:09:52 PM
Comment:
Very goood explanation step by step. This really helped me out. If you can kindly explain the same way creating parameters fields programatically that would be really great.

Thanks&Regards
Title: Creating Parameter fields in Crystal Reports   
Name: Mobius
Date: 8/28/2009 2:05:52 PM
Comment:
oh man this helped me a lot because i've just started to use/learn Crystal Reports at work!

Thanks for the tutorial
Title: Creating Parameter fields in Crystal Reports   
Name: BK
Date: 8/26/2009 4:25:02 AM
Comment:
Great just what I needed
Title: Creating Parameter fields in Crystal Reports   
Name: Ms. Gail
Date: 8/18/2009 9:24:15 AM
Comment:
Thanks. Wonderful article, easy to follow and most importanly, it works.

Now, if you would post to the get back to the original with the entire data or how to continue using the parameter on the report page. That would be helpful.

Thanks again.

Ms. Gail
Title: MR   
Name: Keith Gough
Date: 8/8/2009 6:06:16 AM
Comment:
The video on this subject plus this presentation have saved me a significant amount of time. Many thanks for this it is much appreciated
Title: Creating Parameter fields in Crystal Reports   
Name: prakash
Date: 8/8/2009 6:00:22 AM
Comment:
Hi Boss, Thank u for helping on Crystal report Parameter fields. One more help from you, i.e I have a button on web page, if i click on it, then it should show the report. In my system, when i m loading crystal report into browser,it is asking user name password etc. How to avoid it. send me the code or suggest me the article. my id : pracash_2001@yahoo.com
Title: muy buen articulo   
Name: jaime tovar
Date: 5/13/2009 12:43:31 PM
Comment:
no se si me puedas ayudar ya tengo mi reporte con parametros en vstdio2008 pero l abarra del reporte al darle imprimir o exportar no me hace nada que debo instalar en mi servidor de hecho ya instale los paquetes que inidcan en la pagina de cristal pero no me funciono mucho agradecere su apoyo mi correo eistan@hotmail.com
Title: Creating Parameter fields in Crystal Reports   
Name: Ndugu
Date: 5/11/2009 6:55:41 AM
Comment:
I followed all the steps but failed to open the sample code because it is of a newer VB.NET version. I am using VB.NET 2003. May you post the code for the Submit button.

Ndugu
Title: problem in refreshing the field   
Name: anirudh gupta
Date: 5/7/2009 8:14:15 AM
Comment:
hello Sir,
how can i refresh the parameter fields when i have an report which is generated on the click event of a button which is placed on the another page and on click of a button paraneters needs to be filled when i click on the back button of the browser it get back on the page and again click on the report button button it will show the same report without prompting for the parameter. so plz help me by sending a mail on the above email..............
Thanks
Anirudh Gupta
anirudh.gupta0511@gmail.com
Title: good   
Name: Taslima Patel
Date: 4/30/2009 6:03:07 AM
Comment:
good
Title: Brother please help   
Name: Al-Hakim A. Usman
Date: 4/29/2009 7:10:28 AM
Comment:
Hi Mohammad,

Brother your article is excellent for there are imporatant things to learned from it. How ever what is the software/application tools you have used in this Tutorial? and what is the crystal report version you are refering to in this tutorial?

I am a new to Crystal report I struggled hard to learn it, but I dont know which Crystal Report Designing application/tool I have to used for creating and designing it.

Please help me out. If you have time please send a copy of the designing tool yuo have used in this tutorial to my email hack33m@hotmail.com so that i can install it to my computer.

Thank you very much and hope to hear from you soon..
Title: Programmer Career   
Name: Justin
Date: 4/28/2009 2:05:14 PM
Comment:
This really helped me better under stand Crystal Reports! Thanks!

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 4/23/2014 4:02:32 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search