Results 1 to 5 of 5

Thread: Passing Multiple Crystal Report Parameters

  1. #1
    New Member
    Join Date
    Sep 09
    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,292

    Re: Passing Multiple Crystal Report Parameters

    Moved To Reporting
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    Member
    Join Date
    Dec 08
    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
    New Member
    Join Date
    Sep 09
    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 07
    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
  •