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): 17952/ 602
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

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 6 and 2 and type the answer here:

User Comments

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-2010 ASPAlliance.com  |  Page Processed at 3/19/2010 9:39:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search