Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing crystal report parameter

Status
Not open for further replies.

saadabc

Programmer
Aug 5, 2004
107
US

i have a crystal report that is running off a SQL Server stored procedure. The stored procedure takes 3 parameters. when i add the stored procedure in the crystal report - the parameters automatically appear in the report (under Parameter fields) .... as

@database
@fromdate
@todate



now when i try to set the parameters in vb .net using this code:



Dim paramFields As ParameterFields
paramFields = crReportViewer.ParameterFieldInfo
Dim paramField As New ParameterField
Dim curValues As ParameterValues = paramField.CurrentValues
Try
paramField = paramFields("@database")

Catch ex As Exception
MsgBox(ex.ToString)
End Try

Dim discreteValue As ParameterDiscreteValue = New ParameterDiscreteValue

discreteValue.Value = ReportCriteria


I get an error:

"Object Reference Not Set to An Instance of an object" at the line:

paramField = paramFields("@database")
 
Code:
Try 
  paramField = paramFields.Item("@database")
Catch ex As Exception
  MsgBox(ex.ToString)
End Try

Although the '@' prefix suggests that your looking at a formula field rather than a parameter.

Hope this helps
 
The following has always worked for me:
Code:
Dim cr As New CrystalDecisions.CrystalReports.Engine.ReportDocument

cr.Load("C:\Test.rpt")

Dim pv As New CrystalDecisions.Shared.ParameterValues

Dim pdv As New CrystalDecisions.Shared.ParameterDiscreteValue

pdv.Value = <insert parameter value here, can be any type>

pv.Add(pdv)

cr.DataDefinition.ParameterFields("@database").ApplyCurrentValues(pv)
Note that if you want to pass a null value to a Crystal parameter, you should use Nothing, not DBNull.Value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top