blog

Home / DeveloperSection / Blogs / How to pass parameters with multiples values in crystal report

How to pass parameters with multiples values in crystal report

patrick longila5469 04-Aug-2014
I have a code source using crystal report in visual studio 2008.
I want to display my report with all the values of  parameters which have multiple values.
It displays only the first value instead of many values. I use 2 parameters : periode de paie, matricule. I have problems about the second parameter for displaying all the matricules in my report. A part of my codes is below:


System.EventArgs) Handles Button1.Click
        strcon = "Persist Security Info=False;User ID=sa;Password=administrations;Initial Catalog=gestion_social-inga;server=MAMY-RUTH-PC\MSSQLSERVERNEW"
        connect = New SqlConnection
        connect.ConnectionString = strcon
        connect.Open()
        sql1 = "select * from table_agent_entité ORDER BY [MATR]"
        cmd1 = New SqlCommand(sql1)
        dta1 = New SqlDataAdapter(cmd1)
        cmd1.Connection() = connect
        'remplir le dataset ds avec le contenu dta1
        dta1.Fill(ds, "table_agent_entité")
        'theoriquement affichage du contenu
        objRpt.Load("C:\Windows.old\Users\longila\Documents\Visual Studio 2008\Projects\SOCIALINGA\SOCIALINGA\CrystalReport1.rpt")
        objRpt.SetDataSource(ds)
 
        'passage des paramètres
        Dim paramFields As New ParameterFields()
        Dim paramField As New ParameterField()
        Dim discreteVal As New ParameterDiscreteValue()
 
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue
 
 
        paramField.Name = "MATRICULE"
        ' Définir la première valeur discrète et la transmettre au paramètre
        discreteVal.Value = "E1621"
        paramField.CurrentValues.Add(discreteVal)
        paramFields.Add(paramField)
        crystalReportViewer1.ParameterFieldInfo = paramfields
 
        ' Définir la deuxième valeur discrète et la transmettre au paramètre.
        ' La variable Val prend la valeur new de façon que les valeurs précédentes
        '  ne soient pas remplacées.
        discreteVal = New ParameterDiscreteValue()
        discreteVal.Value = "E2403"
        paramField.CurrentValues.Add(discreteVal)
 
        ' Ajouter le paramètre à la collection de champs de paramètre.
        paramFields.Add(paramField)
        CrystalReportViewer1.ParameterFieldInfo = paramFields
 
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions = _
        objRpt.DataDefinition.ParameterFields()
        crParameterFieldDefinition = _
   crParameterFieldDefinitions.Item("PERIODE DE PAIE")
        crParameterValues = crParameterFieldDefinition.CurrentValues
       crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewer1.ReportSource = objRpt
        CrystalReportViewer1.Refresh()
    End Sub
Can you help me?

Updated 18-Sep-2014
I'm a developer in VB.NET and Crystal Report.

Leave Comment

Comments

Liked By