Sunday, January 25, 2009

Set Parameter in Crystal Reports using ASP.Net

Some one send me a mail and ask for help regarding setting parameters in Crystal Reports using asp.net.

My advice is always to download the web samples at:

Visual Basic .NET Web Samples

C# .NET Web Sample Applications

Then, follow the Readme file to install the “Discrete Parameters” example. This has been my guide, and it works great.

Additional help and tutorials are in the CR SDK:

Crystal Reports .NET SDK – Additional Conceptual Documentation and Tutorials

This file contains additional conceptual information and tutorials for using Crystal Reports in Visual Studio .NET (including a developer reference). This documentation applies to Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003. Sample applications built using these tutorials are available for download (cr_net_sdk_tutorial_samples_en.zip).

Crystal Reports .NET SDK – Sample Applications from Tutorials

This file contains C# and VB .NET Windows and web sample applications. These samples were built using the tutorials provided in the ‘Crystal Reports .NET SDK – Additional Documentation and Tutorials’ (cr_net_sdk_additional_en.zip). These sample applications applies to: Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003.

If you're new to Crystal Reports .NET, get this book:

Crystal Reports .NET Programming

It is both an introduction to Crystal Reports .NET, as well as a object model programming guide/reference. Examples are in both VB.NET and C#.

A number of methods out there use the CrystalReportViewer control to set parameters. That's great unless you need to export your report to PDF (or XLS or RTF). This is a code snippet I use, it comes from Business Objects tech support:

================================================

rptCount = New ReportDocument
rptCount.Load(Server.MapPath("reportname.rpt"))
''Get the collection of parameters from the report
crParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields
''Access the specified parameter from the collection
crParameter1 = crParameterFieldDefinitions.Item("Param1")
crParameter2 = crParameterFieldDefinitions.Item(“Param2")

''Get the current values from the parameter field. At this point
''there are zero values set.
crParameter1Values = crParameter1.CurrentValues
crParameter2Values = crParameter2.CurrentValues

''Set the current values for the parameter field
crDiscrete1Value = New ParameterDiscreteValue
crDiscrete1Value.Value = Request.Form(“param1value“)

crDiscrete2Value = New ParameterDiscreteValue
crDiscrete2Value.Value = Request.Form(“param2value“)

''Add the first current value for the parameter field
crParameter1Values.Add(crDiscrete1Value)
crParameter2Values.Add(crDiscrete2Value)

''All current parameter values must be applied for the parameter field.
crParameter1.ApplyCurrentValues(crParameter1Values)
crParameter2.ApplyCurrentValues(crParameter2Values)

=========================================

Once you get used to working with parameters, you can “automagically” display them on your web pages. This series of articles shows you how to get a list of parameters from your report file, and display them on your web form, where you can prompt for inputs:

Automagically displaying a Crystal Reports Parameters - Part I
Automagically displaying a Crystal Reports Parameters - Part II

Support: http://aspadvice.com/blogs/rjdudley/archive/2005/02/21/2554.aspx

You can add comments regarding this article.

Thanks & Regards,
Vijay Modi

No comments:

Post a Comment