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
Re: Passing Multiple Crystal Report Parameters
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.
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)
Re: Passing Multiple Crystal Report Parameters
THanks F1Neil for the solution, it's perfect.