Results 1 to 5 of 5

Thread: Passing Multiple Crystal Report Parameters

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    2

    Passing Multiple Crystal Report Parameters

    Hi

    I have read a number of threads on this but can't seem to find one that matches the problem i am having. I am trying to pass multiple parameters to a crystal report which seems to work fine and doesn't display any errors or parameter prompts, however all the parameters on the report are displaying the same value. That being the value of the last parameter added to the parameterfields variable. My code is below.

    Code:
     Dim RepReferralsB As New AppropriateReferralTO
                Dim pFields As New ParameterFields
                Dim disval As New ParameterDiscreteValue
                Dim pField1, pField2, pField3 As New ParameterField
    
                pField1.Name = "datStart"
                disval.Value = StartDate
                pField1.CurrentValues.Add(disval)
                pFields.Add(pField1)
    
                pField2.Name = "datEnd"
                disval.Value = EndDate
                pField2.CurrentValues.Add(disval)
                pFields.Add(pField2)
    
                pField3.Name = "RefType"
                disval.Value = RefType
                pField3.CurrentValues.Add(disval)
                pFields.Add(pField3)
    
                RepReferralsB.SetDataSource(dsData)
                ReportViewer.ReportSource = RepReferralsB
                ReportViewer.ParameterFieldInfo = pFields
    Any help appreciated.

    Thanks

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Passing Multiple Crystal Report Parameters

    Moved To Reporting

  3. #3
    Member
    Join Date
    Dec 2008
    Posts
    33

    Re: Passing Multiple Crystal Report Parameters

    I believe the reason for this is that you are reusing the parameter disval for the value of the parameters

    The code
    pField1.CurrentValues.Add(disval) is adding the object disVal to the colection CurrentValues

    It is adding the object rather than just the value therefore any changes that are made to disval will also be reflected in anything it has been added to.

    Try something like

    Dim disval1 As New ParameterDiscreteValue
    Dim disval2 As New ParameterDiscreteValue
    Dim disval3 As New ParameterDiscreteValue

    and set the 3 values appropriately.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    2

    Resolved Re: Passing Multiple Crystal Report Parameters

    Thanks for the reply, i had just figured it out after some further investigation.
    Here is the working code for completeness.

    Code:
                Dim RepReferralsB As New AppropriateReferralTO
                Dim pFields As New ParameterFields
                Dim disval1, disval2, disval3 As New ParameterDiscreteValue
                Dim pField1, pField2, pField3 As New ParameterField
    
                pField1.Name = "datStart"
                disval1.Value = StartDate
                pField1.CurrentValues.Add(disval1)
                pFields.Add(pField1)
    
                pField2.Name = "datEnd"
                disval2.Value = EndDate
                pField2.CurrentValues.Add(disval2)
                pFields.Add(pField2)
    
                pField3.Name = "RefType"
                disval3.Value = RefType
                pField3.CurrentValues.Add(disval3)
                pFields.Add(pField3)
    
                RepReferralsB.SetDataSource(dsData)
                ReportViewer.ReportSource = RepReferralsB
                ReportViewer.ParameterFieldInfo = pFields
                ReportViewer.Zoom(1)

  5. #5
    New Member gdcats's Avatar
    Join Date
    Sep 2007
    Location
    Dubai UAE
    Posts
    5

    Re: Passing Multiple Crystal Report Parameters

    THanks F1Neil for the solution, it's perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width