How to pass parameters to crystal report at runtime.


This article helps about how to pass parameters to crystal report at runtime with code snippet

This example shows how to pass parameters to Crystal reports at runtime.

First create crystal report. In the interface of report (.aspx form) to display report, add report document through Toolbox-->Components-->ReportDocument.

Call the sub routine CreatePDF to display report.

rptProduct is the name of crystal report and docProd is the name of report document.

Add a blank formula in the cyrstal report.This formula should not be running formula.


Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

'This call is required by the Web Form Designer.
Private Sub InitializeComponent()
'start - This code should be pasted under #Region Private Sub itializeComponent()
'rptProduct is the name of crystal report.
Me.docProd = New rptProduct
'
'docProd
'
Me.docProd.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation
Me.docProd.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize
Me.docProd.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper
Me.docProd.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default
'Ends here

'Declaration of report document
Protected WithEvents docProd As rptProduct

Private Sub CreatePDF()
Dim objDS As New DataSet
Dim dfdoFile As New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim strServerPath As String
Dim szFileName As String


'Create dataset as per requirement

docProd.SetDataSource(objDS.Tables(0))

szFileName = Session.SessionID & ".pdf" ' rptDailyCalls.pdf
strServerPath = MapPath("~") & "\Report\" ' Here the pdf file will be saved.
File.Delete(strServerPath & "\" & szFileName) ' Delete file first
dfdoFile.DiskFileName = strServerPath & "\" & szFileName
docProd.DataDefinition.FormulaFields("DispFromDate").Text = "Date(" & Format(Date.Now,"dd/MM/yyyy") & ")"
'Here DispFromDate is the name of blank formula
With docProd
.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
.ExportOptions.DestinationOptions = dfdoFile
.Export()
End With
'URL of the pdf file
Response.Redirect("http://localhost/WebApplication1/" & szFileName ,Flase)
End Sub




Comments

Author: JodiBahu16 Sep 2011 Member Level: Bronze   Points : 1

Hi Author,
this is a great article, thanks for sharing with us.
here you may check out, how to pass parameter to crystal report at runtime using c#.Please copy and paste following links into web browser....

www.mindstick.com/Articles/125cbf8f-f1e5-44a7-b3ca-41450a3fbd18/?Dynamically%20pass%20parameter%20value%20in%20Crystal%20Report

Thanks !!!!

Guest Author: rajesh21 Feb 2012

Good Article



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: