Skip to Content
avatar image
Former Member

Problem with passing multiple discrete values to a parameter

I am struggling to get the passing of multiple discrete values to a parameter field to work. Single discrete and single ranged parameters are working fine, but despite trying all examples I can find (and there's not many) I can't get it to work. Can anyone see what is going wrong in my code below, please?

This is running against CR Server 2013 and it is lines 36-45 that are the issue. The code steps through the parameters found in the report and looks for URL/Form values with matching names. The multiple value capable fields are supplied with comma delimited lists of strings in the URL/Form values.

Private Sub DatabaseLogon_unmanagedRAS()
  Dim mySampleReportPath As String = Request("rpt__rpt")
  Dim path As Object = CType(mySampleReportPath, String)
  Dim rptFile As String = path.Substring(8)
  Dim databaseUserName As String = Request("rpt__un")
  Dim databasePassword As String = Request("rpt__pw")   Dim rcd As New ReportClientDocumentClass()
  Dim pfld As String
  Dim pfldName As String       
  Dim crMainReportParameterFields As Fields
  Dim crField As Field
  Dim arrKeys() As String
  Dim newVal As ParameterDiscreteValue
  Dim crDiscreteVal As CrystalDecisions.Shared.ParameterDiscreteValue    rcd.ReportAppServer = "localhost:6420"
   rcd.Open(rptFile, 0)
   rcd.DatabaseController.logon(databaseUserName, databasePassword)
   crMainReportParameterFields = rcd.DataDefinition.ParameterFields

   For Each crField In crMainReportParameterFields
    pfldName = crField.Name.ToString
    Try
     Select Case crField.ValueRangeKind
      'Ranged parameter.
      Case 0
       Dim crRangeVal As ParameterFieldRangeValue = New ParameterFieldRangeValue()
       pfld = Request(pfldName)
       arrKeys = pfld.Split("|")
       crRangeVal.BeginValue = arrKeys(0)
       crRangeVal.EndValue = arrKeys(1)
       crRangeVal.LowerBoundType = RangeBoundType.BoundInclusive
       crRangeVal.UpperBoundType = RangeBoundType.BoundInclusive
       rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crRangeVal)
      'Discrete parameter.
      Case 1
       If crField.AllowMultiValue Then ' multiple values
        Dim crParameterValues As ParameterValues = New ParameterValues()
        pfld = Request(pfldName)
        arrKeys = pfld.Split(",")
        For Each multiVal As String In arrKeys
          crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
          crDiscreteVal.value = multiVal.toString()
          crField.CurrentValues.Add(crDiscreteVal)
        Next
       Else ' single value
        crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
        crDiscreteVal.Value = Request(pfldName)
        rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crDiscreteVal)
       End If
     End Select
    Catch ex As Exception
     Response.Write("<b><u>The report viewer has encountered an error:</u></b><br><br>")
     Response.Write(ex.Message)
     Response.Write("Stack Trace: " & vbCrLf & ex.StackTrace)
     rcd.Close()
    Finally
      'do cleanup
    End Try
   Next

   'Debug_showParams(crMainReportParameterFields)
 
   myCrystalReportViewer.ReportSource = rcd
 
   myCrystalReportViewer.HasRefreshButton = true
    End Sub
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 02, 2015 at 02:25 PM

    Hi Dave,

    What SDK package are you using?

    What is the actual error you are getting?

    Don

    Add comment
    10|10000 characters needed characters exceeded

    • Dave, it boils down to

      Dim currentParameterValues As ParameterValues = New ParameterValues()

      Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()

      Looping through your multiple values doing:

      ---

      myParameterDiscreteValue.Value = submittedValue.ToString()

      currentParameterValues.Add(myParameterDiscreteValue)

      ---

      and then,

      myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues)

  • avatar image
    Former Member
    Nov 05, 2015 at 04:15 PM

    Thanks for that Ido, I have now applied that and tried it, but still getting an error. My loop now looks like this:

     
     
    1.    rcd.Open(rptFile, 0) 
    2.    rcd.DatabaseController.logon(databaseUserName, databasePassword) 
    3.    crMainReportParameterFields = rcd.DataDefinition.ParameterFields
    For Each crField In crMainReportParameterFields
        pfldName = crField.Name.ToString
        Try
         Select Case crField.ValueRangeKind
          'Ranged parameter.
          Case 0
           Dim crRangeVal As ParameterFieldRangeValue = New ParameterFieldRangeValue()
           pfld = Request(pfldName)
           arrKeys = pfld.Split("|")
           crRangeVal.BeginValue = arrKeys(0)
           crRangeVal.EndValue = arrKeys(1)
           crRangeVal.LowerBoundType = RangeBoundType.BoundInclusive
           crRangeVal.UpperBoundType = RangeBoundType.BoundInclusive
           rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crRangeVal)
          'Discrete parameter.
          Case 1
           If crField.AllowMultiValue Then
            Dim currentParameterValues As ParameterValues = New ParameterValues()
            Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
            pfld = Request(pfldName)
            arrKeys = pfld.Split(",")
            For Each multiVal As String In arrKeys
             myParameterDiscreteValue.Value = multiVal.ToString()
             currentParameterValues.Add(myParameterDiscreteValue)         Next
            crField.ApplyCurrentValues(currentParameterValues)
           Else
            crDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
            crDiscreteVal.Value = Request(pfldName)
            rcd.DataDefController.ParameterFieldController.SetCurrentValue("", pfldName, crDiscreteVal)
           End If
         End Select
        Catch ex As Exception
         Response.Write("<b><u>The report viewer has encountered an error:</u></b><br><br>")
         Response.Write(ex.Message)
         Response.Write("Stack Trace: " & vbCrLf & ex.StackTrace)
         rcd.Close()
        Finally
          'do cleanup
        End Try
       Next

    Ii am getting the error:

    The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))Stack Trace: at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) at _ViewRpt.DatabaseLogon_unmanagedRAS() in C:\inetpub\wwwroot\taser\report\ras\ViewRpt.aspx.vb:line 102

    Is the crField item in the collection I am looping though (rcd.DataDefinition.ParameterFields) the same entity as your example "myParameterFieldDefinition."?

    Add comment
    10|10000 characters needed characters exceeded