locked
Passing Multiple Parameters RRS feed

  • Question

  • User1556928295 posted

    I'm trying to pass several parameters to a Crystal Report, but it seems to always send nothing to the report. I step though and it seems to work, but at the last minute it just sends nothing.

            If Selected = "Pending Applicants" Then
                Dim paramFields As New ParameterFields()
                Dim paramField As New ParameterField()
                Dim discreteVal As New ParameterDiscreteValue()

                paramField.ParameterFieldName = "@Handler_Technician" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = ""
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Handler_Technician_Eligible" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = ""
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Status1" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = "PAPP"
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Status2" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = "PBND"
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Status3" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = "PDNY"
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Status4" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = "PEND"
                'Value of Parameter
                paramField.CurrentValues.Add(discreteVal)

                paramField.ParameterFieldName = "@Status_Dt" ' This is how you can send Parameter Value to the Crystal Report

                discreteVal.Value = DBNull.Value
                'Value of Parameter

                paramField.CurrentValues.Add(discreteVal)

                paramFields.Add(paramField)

                CrystalReportViewer3.ParameterFieldInfo = paramFields
                ReportBtnPanel_ModalPopupExtender.Show()
                CrystalReportViewer3.Visible = True
                GridView1.Visible = True
            End If

    What am I doing wrong here?

    Friday, April 18, 2014 12:03 PM

Answers

  • User1556928295 posted

    I had to break it all down tothe individual parameters like so;

            If Selected = "Pending Applicants" Then
                Dim rptCount As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

                'rptCount = New ReportDocument
                rptCount.Load(Server.MapPath("~\Reports\cryVls1a22.rpt"))
                rptCount.SetDatabaseLogon("XXXXX", "XXXXXXX")

                'Get the collection of parameters from the report
                Dim crParameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields

                'Access the specified parameter from the collection
                Dim crParameter1 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Handler_Technician")
                Dim crParameter2 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Handler_Technician_Eligible")
                Dim crParameter3 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status1")
                Dim crParameter4 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status2")
                Dim crParameter5 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status3")
                Dim crParameter6 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status4")
                Dim crParameter7 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status_Dt")

                'Get the current values from the parameter field. At this point
                'there are zero values set.
                Dim crParameter1Values As CrystalDecisions.Shared.ParameterValues = crParameter1.CurrentValues
                Dim crParameter2Values As CrystalDecisions.Shared.ParameterValues = crParameter2.CurrentValues
                Dim crParameter3Values As CrystalDecisions.Shared.ParameterValues = crParameter3.CurrentValues
                Dim crParameter4Values As CrystalDecisions.Shared.ParameterValues = crParameter4.CurrentValues
                Dim crParameter5Values As CrystalDecisions.Shared.ParameterValues = crParameter5.CurrentValues
                Dim crParameter6Values As CrystalDecisions.Shared.ParameterValues = crParameter6.CurrentValues
                Dim crParameter7Values As CrystalDecisions.Shared.ParameterValues = crParameter7.CurrentValues

                'Set the current values for the parameter field
                Dim disVal1 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal2 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal3 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal4 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal5 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal6 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal7 As New CrystalDecisions.Shared.ParameterDiscreteValue()

                disVal1.Value = ""
                disVal2.Value = ""
                disVal3.Value = "PAPP"
                disVal4.Value = "PBND"
                disVal5.Value = "PDNY"
                disVal6.Value = "PEND"
                disVal7.Value = DBNull.Value

                'Add the first current value for the parameter field
                crParameter1Values.Add(disVal1)
                crParameter2Values.Add(disVal2)
                crParameter3Values.Add(disVal3)
                crParameter4Values.Add(disVal4)
                crParameter5Values.Add(disVal5)
                crParameter6Values.Add(disVal6)
                crParameter7Values.Add(disVal7)

                'All current parameter values must be applied for the parameter field.
                crParameter1.ApplyCurrentValues(crParameter1Values)
                crParameter2.ApplyCurrentValues(crParameter2Values)
                crParameter3.ApplyCurrentValues(crParameter3Values)
                crParameter4.ApplyCurrentValues(crParameter4Values)
                crParameter5.ApplyCurrentValues(crParameter5Values)
                crParameter6.ApplyCurrentValues(crParameter6Values)
                crParameter7.ApplyCurrentValues(crParameter7Values)

                CrystalReportViewer3.ReportSource = rptCount

                ReportBtnPanel_ModalPopupExtender.Show()
                CrystalReportViewer1.Visible = False
                CrystalReportViewer2.Visible = False
                CrystalReportViewer3.Visible = True
                GridView1.Visible = True
                GridView2.Visible = False
                GridView3.Visible = False
            End If

    And now it's working like a charm.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 18, 2014 2:50 PM

All replies

  • User-993404089 posted

    First make sure that your parameter field name includes the '@' in Crystal Report.

    If it does.  How do you know that it is not passing anything.  Where have you looked to see this

    Where is the code that sets the CrystalReport to the name of the Crystal Report?

    Try this...http://forums.asp.net/t/1432158.aspx?Passing+Parameters+to+Crystal+Report+Programmatically

    Friday, April 18, 2014 2:45 PM
  • User1556928295 posted

    I had to break it all down tothe individual parameters like so;

            If Selected = "Pending Applicants" Then
                Dim rptCount As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

                'rptCount = New ReportDocument
                rptCount.Load(Server.MapPath("~\Reports\cryVls1a22.rpt"))
                rptCount.SetDatabaseLogon("XXXXX", "XXXXXXX")

                'Get the collection of parameters from the report
                Dim crParameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields

                'Access the specified parameter from the collection
                Dim crParameter1 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Handler_Technician")
                Dim crParameter2 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Handler_Technician_Eligible")
                Dim crParameter3 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status1")
                Dim crParameter4 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status2")
                Dim crParameter5 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status3")
                Dim crParameter6 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status4")
                Dim crParameter7 As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition = crParameterFieldDefinitions.Item("@Status_Dt")

                'Get the current values from the parameter field. At this point
                'there are zero values set.
                Dim crParameter1Values As CrystalDecisions.Shared.ParameterValues = crParameter1.CurrentValues
                Dim crParameter2Values As CrystalDecisions.Shared.ParameterValues = crParameter2.CurrentValues
                Dim crParameter3Values As CrystalDecisions.Shared.ParameterValues = crParameter3.CurrentValues
                Dim crParameter4Values As CrystalDecisions.Shared.ParameterValues = crParameter4.CurrentValues
                Dim crParameter5Values As CrystalDecisions.Shared.ParameterValues = crParameter5.CurrentValues
                Dim crParameter6Values As CrystalDecisions.Shared.ParameterValues = crParameter6.CurrentValues
                Dim crParameter7Values As CrystalDecisions.Shared.ParameterValues = crParameter7.CurrentValues

                'Set the current values for the parameter field
                Dim disVal1 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal2 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal3 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal4 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal5 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal6 As New CrystalDecisions.Shared.ParameterDiscreteValue()
                Dim disVal7 As New CrystalDecisions.Shared.ParameterDiscreteValue()

                disVal1.Value = ""
                disVal2.Value = ""
                disVal3.Value = "PAPP"
                disVal4.Value = "PBND"
                disVal5.Value = "PDNY"
                disVal6.Value = "PEND"
                disVal7.Value = DBNull.Value

                'Add the first current value for the parameter field
                crParameter1Values.Add(disVal1)
                crParameter2Values.Add(disVal2)
                crParameter3Values.Add(disVal3)
                crParameter4Values.Add(disVal4)
                crParameter5Values.Add(disVal5)
                crParameter6Values.Add(disVal6)
                crParameter7Values.Add(disVal7)

                'All current parameter values must be applied for the parameter field.
                crParameter1.ApplyCurrentValues(crParameter1Values)
                crParameter2.ApplyCurrentValues(crParameter2Values)
                crParameter3.ApplyCurrentValues(crParameter3Values)
                crParameter4.ApplyCurrentValues(crParameter4Values)
                crParameter5.ApplyCurrentValues(crParameter5Values)
                crParameter6.ApplyCurrentValues(crParameter6Values)
                crParameter7.ApplyCurrentValues(crParameter7Values)

                CrystalReportViewer3.ReportSource = rptCount

                ReportBtnPanel_ModalPopupExtender.Show()
                CrystalReportViewer1.Visible = False
                CrystalReportViewer2.Visible = False
                CrystalReportViewer3.Visible = True
                GridView1.Visible = True
                GridView2.Visible = False
                GridView3.Visible = False
            End If

    And now it's working like a charm.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 18, 2014 2:50 PM