PDA

Click to See Complete Forum and Search --> : Crystal Report&vb.net Parameter passing to formula field in rpt file


dharmaraju
Jun 20th, 2007, 04:35 AM
Hi everbody


I am trying vb.net & Crystal for my further projects but i am not able to pass value to formula field in crystal report rpt file from my form which is calling the rpt


Thanks & Regards

Asgorath
Jun 22nd, 2007, 05:04 AM
Hi. Here a sample extracted from 101 VB.NET Samples.

Imports CrystalDecisions.CrystalReports.Engine
Private Sub btnPreviewCustomerReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviewCustomerReport.Click
' In this event the Customer Orders Report is loaded
' and displayed in the crystal reports viewer.
' This report calls for a parameter which is pulled
' from the customer name combo box (cbCustomers).

' Objects used to set the parameters in the report
Dim pvCollection As New CrystalDecisions.Shared.ParameterValues()
Dim pdvCustomerName As New CrystalDecisions.Shared.ParameterDiscreteValue()

' Objects used to set the proper database connection information
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

' Create a report document instance to hold the report
Dim rptCustomersOrders As New ReportDocument()

Try
' Load the report
rptCustomersOrders.Load("..\CustomerOrders.rpt")

' Set the connection information for all the tables used in the report
' Leave UserID and Password blank for trusted connection
For Each tbCurrent In rptCustomersOrders.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = ServerName
.UserID = ""
.Password = ""
.DatabaseName = "Northwind"
End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent

' Set the discreet value to the customers name.
pdvCustomerName.Value = cbCustomers.Text

' Add it to the parameter collection.
pvCollection.Add(pdvCustomerName)

' Apply the current parameter values.
rptCustomersOrders.DataDefinition.ParameterFields("@CustomerName").ApplyCurrentValues(pvCollection)

' Hide group tree for this report
crvParameter.DisplayGroupTree = False

' Set the report source for the crystal reports viewer to the
' report instance.
crvParameter.ReportSource = rptCustomersOrders

' Zoom viewer to fit to the whole page so the user can see the report
crvParameter.Zoom(2)

Catch Exp As LoadSaveReportException
MsgBox("Incorrect path for loading report.", _
MsgBoxStyle.Critical, "Load Report Error")

Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")

End Try
End Sub