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!

Prolems with the CrystalDecisions.Shared.ParameterField Collection

Status
Not open for further replies.

richmond88

IS-IT--Management
Sep 25, 2003
32
GB
I I am going through the David McAmis - Crystal Reports XI for Developers book and I am upto Ch9 - Integrating Reports into Windows Applications. Specifically "ParameterField.Name" which is in the bottom line of this code. VB tells me that it is not a member of CrystalDecisions.Shared.ParameterField. Any ideas gratefully received.


Dim ParameterFields As CrystalDecisions.Shared.ParameterFields

Dim ParameterField As
CrystalDecisions.Shared.ParameterField

ParameterFields = CrystalReportViewer1.ParameterFieldInfo
Dim DisplayText

For Each ParameterField In ParameterFields
DisplayText = "Parameter Name: " & ParameterField.Name & Chr(13)
 
I can recall enjoying? many hours of fun finding a way to ensure that parameters always worked for me. Im sure there are many ways to achieve the same result, but I have found that the code below always works for me. In my code, I pass in a Hashtable, where the key is the parameter name, and the value is the parameter value. I suffix the parameters with s for string type, i for integer type etc.
In my code you can substitute Me.oreport.oreport for your Crystal report object. I always add the parameters to the report itself, then pass this entire info into the viewer.
Code:
Private Sub zProcessParameters(ByVal ht As Hashtable)

For Each de As DictionaryEntry In ht

Dim sType As String = CStr(de.Key).ToLower.Substring(0, 1)

Dim oValue As Object
Select Case sType
    Case "b"
        oValue = CBool(de.Value)
    Case "i"
        oValue = CInt(de.Value)
    Case "d"
        oValue = CDbl(de.Value)
    Case Else
        oValue = CStr(de.Value)
End Select
 
'Find the Parameter in the Reports Data Collection and Set it, if Found
Dim pdef As ParameterFieldDefinition
Dim pval As New ParameterValues
For i As Integer = 0 To Me.oReport.oReport.DataDefinition.ParameterFields().Count - 1
   pdef = Me.oReport.oReport.DataDefinition.ParameterFields(i)
   If pdef.Name.ToLower = CStr(de.Key).ToLower Then
       pdef.CurrentValues.Clear()
       pval.AddValue(oValue)
       pdef.ApplyCurrentValues(pval)
   End If
Next

Next

'Set the Viewer to the Parameters Collection
xViewer.ParameterFieldInfo = Me.oReport.oReport.ParameterFields

End Sub



Sweep
...if it works dont f*** with it
curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top