Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: Passing multi select parameters in asp.net Post Reply Post New Topic
Author Message
yasinirshad
Newbie
Newbie
Avatar

Joined: 24 Sep 2007
Location: Saudi Arabia
Online Status: Offline
Posts: 39
Quote yasinirshad Replybullet Topic: Passing multi select parameters in asp.net
    Posted: 31 May 2008 at 3:46am
Hi,
how to pass multi select paramteres in asp.net..
 I will have 3 Paramters i.e., on my webform user will select
*. startdate and enddate
*. Division
*. Department
If user had selected one division (ex: Fin) and one department(ex: Finance) then i would not have any problem.
But here user can select multiple division (ex: Fin,IT,HR) and multiple departments (ex: Finance,Information.Tech,Human Resources) then how to pass this multiple paramters in asp.net?
I have sample code which i used in previous project for passing single parameters..below is code,
Below am passing Date (Period), ProjectNo and SupplierCode (Here user can select only one Project No and SupplierCode).
Try
            If ConState = False Then
                Connect()
            End If
            Dim ConnInfo As New ConnectionInfo
            With ConnInfo
                .ServerName = mOleDB.strServerName
                .DatabaseName = mOleDB.strDBName
                .UserID = mOleDB.strUsrName
                .Password = mOleDB.strUsrPwd
            End With
            ' Declare variables needed to pass the parameters
            ' to the viewer control.
            Dim paramFields As New ParameterFields
            Dim paramField As New ParameterField
            Dim discreteVal As New ParameterDiscreteValue
            Dim rangeVal As New ParameterRangeValue
            ' Set the name of the parameter field, this must match a
            ' parameter in the report. (Date Parameter)
            paramField.ParameterFieldName = "Period"
            ' Set the start and end values of the range and pass it to the 'parameter.
            rangeVal.StartValue = ClosedReport.StartDate
            rangeVal.EndValue = ClosedReport.EndDate
            paramField.CurrentValues.Add(rangeVal)
            ' Add the first parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' The second parameter is a discrete value. The paramField variable
            ' is set to new so the previous settings will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "ProjectNo"
            ' Set the first discrete value and pass it to the parameter based on conditions.
            If ClosedReport.ProjectNo <> "" Then
                discreteVal.Value = ClosedReport.ProjectNo
            Else
                discreteVal.Value = "*"
            End If
            paramField.CurrentValues.Add(discreteVal)
            ' Add the parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' Set the second discrete value and pass it to the parameter.
            ' The discreteVal variable is set to new so the previous settings
            ' will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "SupplierCode"
            discreteVal = New ParameterDiscreteValue
            ' Set the second discrete value and pass it to the parameter based on conditions.
            If ClosedReport.SupplierCode <> "" Then
                discreteVal.Value = ClosedReport.SupplierCode
            Else
                discreteVal.Value = "*"
            End If
            paramField.CurrentValues.Add(discreteVal)
            ' Add the parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' Set the parameter fields collection into the viewer control.
            CrystalReportViewer_SuppProjOpen.ParameterFieldInfo = paramFields
            CrystalReportViewer_SuppProjOpen.ReportSource = crReportDocument
            For Each cnInfo As TableLogOnInfo In Me.CrystalReportViewer_SuppProjOpen.LogOnInfo
                cnInfo.ConnectionInfo = ConnInfo
            Next
            'Me.CrystalReportViewer_SuppProjClosed.RefreshReport()
            CrystalReportViewer_SuppProjOpen.Visible = True
        Catch err As System.Exception
            MessageBox.Show(err.Message, "System error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
 
Thanks to help.
Thanks,
Yasin.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 31 May 2008 at 8:19pm
Unfortuanately, CR doesn't let you pass multi-value parameters to a report. You can only pass discrete values or range values. One option is to pass a comma delimited string to CR and then use the Split() function to convert the string to a CR array variable.

I have extensive coverage of arrays and a reference of array functions in my Encyclopedia book. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
yasinirshad
Newbie
Newbie
Avatar

Joined: 24 Sep 2007
Location: Saudi Arabia
Online Status: Offline
Posts: 39
Quote yasinirshad Replybullet Posted: 01 Jun 2008 at 4:47am
 
Hi,
You said
 "One option is to pass a comma delimited string to CR and then use the Split() function to convert the string to a CR array variable. "
 
Do You mean..If i have a discrete Parameter "Division" whose values are "BD,IT,HR" then i shd do as below...
 
           Dim array As String() = {"BD", "IT", "HR"}
         Dim strSplit() As String = array.Split(",")
 
            ' The parameter is a discrete value. The paramField variable
            ' is set to new so the previous settings will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "Division"
            ' Set the first discrete value and pass it to the parameter 
            discreteVal.Value = frmNCNClosedReport.ProjectNo
           paramField.CurrentValues.Add(discreteVal)
 
And then can u help me pls how to proceed..
Here my Discrete Parameter name is "Division"
 
Pls help.
 
Can you please explain me in little more detail how to do this..
Thanks to help with Code.
Thanks.


Edited by yasinirshad - 01 Jun 2008 at 5:02am
Thanks,
Yasin.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.