Passing Parameters To Crystal Reports

6,553 views
6,381 views

Published on

Published in: Technology
2 Comments
1 Like
Statistics
Notes
  • Hi Everyone, To pass parameter to Crystal report at runtime, please click on following links.....
    http://www.mindstick.com/Articles/125cbf8f-f1e5-44a7-b3ca-41450a3fbd18/?Dynamically%20pass%20parameter%20value%20in%20Crystal%20Report
    Thanks !!!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hey, any chance you add the audio to this slide?
    http://www.furniture101.net/
    http://www.furniture101.net/category/dining-room-furniture/
    http://www.furniture101.net/category/furniture-101/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
6,553
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
73
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Passing Parameters To Crystal Reports

  1. 1. Source : Mindcracker Network (www.c-sharpcorner.com) Passing parameters to Crystal Reports at runtime with c# By Shashi Ray September 29, 2008 This article shows how to pass parameters to a Crystl Reports at runtime in C#. This small article shows how you can create and pass parameters value at runtime in a Crystal Report from your UI. In my application, I am using a ReportViewer control in Visual Studio 2005 to view the report. Note: To learn more about how to generate reports in a ReportViewer, read this free book: Free Book: Reports using Report Viewer in Visual Studio 2005 The main functionality is defined in the ReportParameter method listed below. In this method, I create a ParameterFields object, which is a collection of parameters. ParameterFields paramFields = new ParameterFields(); After that, I create ParameterField, set its name and values and the value I pass is from the DropDownlList on my page. You can pass value from any control you want. ParameterField pfItemYr = new ParameterField(); pfItemYr.ParameterFieldName = quot;yearquot;; //year is Crystal Report Parameter name. ParameterDiscreteValue dcItemYr = new ParameterDiscreteValue(); dcItemYr.Value = DropDownList1.SelectedValue; pfItemYr.CurrentValues.Add(dcItemYr); After that I add parameter to the ParameterFields. If you have multiple parameters, you can create and add them using the similar process. paramFields.Add(pfItemYr); The last step is to set ParameterFieldInfo property of the CrystalReportViewer control to ParameterFields I created. CrystalReportViewer1.ParameterFieldInfo = paramFields; Here is the complete code of the page. using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; public partial class _Default : System.Web.UI.Page
  2. 2. { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings[quot;Helloquot;]); Class1 dbc = new Class1(); protected void Page_Load(object sender, EventArgs e) { CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = quot;ShashiKantRayquot;; CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = quot;saquot;; CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = quot;saquot;; CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = quot;Shashiquot;; ReportParameter(); } private void ReportParameter() { CrystalReportViewer1.RefreshReport(); ParameterFields paramFields = new ParameterFields(); ParameterField pfItemYr = new ParameterField(); pfItemYr.ParameterFieldName = quot;yearquot;; //year is Crystal Report Parameter name. ParameterDiscreteValue dcItemYr = new ParameterDiscreteValue(); dcItemYr.Value = DropDownList1.SelectedValue; pfItemYr.CurrentValues.Add(dcItemYr); paramFields.Add(pfItemYr); CrystalReportViewer1.ParameterFieldInfo = paramFields; } } Note: To learn more about how to generate reports in a ReportViewer, read this free book: Free Book: Reports using Report Viewer in Visual Studio 2005 Thank you for using Mindcracker Network

×