locked
Passing multiple Parameter to Crystal Report

    Question

  • Dear friends, Please i have this code below which pass just one fields as  paramter to crystal report, but i want to passes two field to the crystal report

    I dont have an idea of what to do pls kindly look thru my code  and tell what i should do

    Note: the below code is working perfectly for one field parameter


    Private Sub frmReportsViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                Dim cryReport As New ReportDocument
                Dim crTableLogonInfos As New TableLogOnInfos
                Dim crTableLogonInfo As New TableLogOnInfo
                Dim crConnectionInfo As New ConnectionInfo
                Dim crTables As Tables
                Dim crTable As Table

                cryReport.Load(Application.StartupPath & "\Reports\" & pubReportName)

                'Assign the Database connection information
                With crConnectionInfo
                    .ServerName = "jemmc_whoas_db"
                    .DatabaseName = "JEMMC_WHOAS_DB"
                    .UserID = "sa"
                    .Password = "admin"
                End With

                crTables = cryReport.Database.Tables
                For Each crTable In crTables
                    crTableLogonInfo = crTable.LogOnInfo
                    crTableLogonInfo.ConnectionInfo = crConnectionInfo
                    crTable.ApplyLogOnInfo(crTableLogonInfo)
                Next


                Dim crPramFieldDeftns As ParameterFieldDefinitions
                Dim crPramFieldDeftn As ParameterFieldDefinition
                Dim crPramVal As New ParameterValues
                Dim crPramDescVal As New ParameterDiscreteValue
                crPramDescVal.Value = pubPramVal1
                crPramFieldDeftns = cryReport.DataDefinition.ParameterFields
                crPramFieldDeftn = crPramFieldDeftns.Item(pubPramCryName)
                crPramVal.Clear()
                crPramVal.Add(crPramDescVal)
                crPramFieldDeftn.ApplyCurrentValues(crPramVal)

                CrystalReportViewer.ReportSource = cryReport
                CrystalReportViewer.Refresh()

            Catch ex As Exception
                MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub

    Monday, August 10, 2009 11:28 AM

Answers

  • you can do it in a easy way.

    remove

    Dim crPramFieldDeftns As ParameterFieldDefinitions
                Dim crPramFieldDeftn As ParameterFieldDefinition
                Dim crPramVal As New ParameterValues
                Dim crPramDescVal As New ParameterDiscreteValue
                crPramDescVal.Value = pubPramVal1
                crPramFieldDeftns = cryReport.DataDefinition.ParameterFields
                crPramFieldDeftn = crPramFieldDeftns.Item(pubPramCryName)
                crPramVal.Clear()
                crPramVal.Add(crPramDescVal)
                crPramFieldDeftn.ApplyCurrentValues(crPramVal)

    just replace it with:

    myreport.SetParameterValue("xx1", "test1")
    myreport.SetParameterValue("xx2", "test2")

    xx1 or xx2 is the cr parameter's name,test1 or test2 is the value
    • Marked as answer by Harry Zhu Monday, August 17, 2009 8:10 AM
    Monday, August 10, 2009 11:48 PM