Click here to Skip to main content
15,891,423 members

Getting Error: Missing Parameter Values

Eddi Rae asked:

Open original thread
I am new to using Crystal in VB.net. I have multiple parameters. Some of them have multiple values. I have viewed several sites with suggestions on how to pass these parameters from vb.net to the crystal report viewer and the report. Below is my code. I am not sure what is incorrect with it.

VB
Imports System.Data
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Imports System.Data.OleDb

    Protected Sub cmdRunReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRunReport.Click
            Dim dtFromDate As Date
            Dim dtToDate As Date
            Dim strFromDate As String
            Dim strToDate As String
            Dim strDateRange As String
            Dim rptDoc As New ReportDocument

            Dim myPath As String
            Dim crUser As String
            Dim crPwd As String
            Dim crServer As String
            Dim crDatabase As String
            Dim bAll As String
            Dim iCnt As Integer

            txtMsg.Visible = False
            txtMsg.Text = Nothing

            crUser = ConfigurationManager.AppSettings("crUser").ToString
            crPwd = ConfigurationManager.AppSettings("crPwd").ToString
            crServer = ConfigurationManager.AppSettings("crServer").ToString
            crDatabase = ConfigurationManager.AppSettings("crDatabase").ToString

            If ddlReport.SelectedValue = -1 Then
                txtMsg.Text = "You must select a report to preview"
                txtMsg.Visible = True
                ddlReport.Focus()
                Exit Sub
            End If

            dtFromDate = Me.calFromDate.SelectedDate.Date
            If Not IsDate(dtFromDate) Then
                txtMsg.Text = "You must select a from date"
                txtMsg.Visible = True
                calFromDate.Focus()
                Exit Sub
            End If
            dtToDate = Me.calToDate.SelectedDate.Date
            If Not IsDate(dtToDate) Then
                txtMsg.Text = "You must select a to date"
                txtMsg.Visible = True
                calToDate.Focus()
                Exit Sub
            End If

            myPath = Nothing
            Select Case ddlReport.SelectedValue
                Case "106"
                    'Load the selected report file
                    myPath = Server.MapPath("Nav106.rpt")
            End Select

            Dim paramFields As ParameterFieldDefinitions
            Dim paramField1 As ParameterFieldDefinition
            Dim paramField2 As ParameterFieldDefinition
            Dim paramField3 As ParameterFieldDefinition
            Dim paramField4 As ParameterFieldDefinition
            Dim paramField5 As ParameterFieldDefinition
            Dim paramField6 As ParameterFieldDefinition
            Dim paramField7 As ParameterFieldDefinition
            Dim DiscreteVal As ParameterDiscreteValue
            Dim paramValues As ParameterValues

            'Load Report
            rptDoc.Load(myPath)

            paramFields = rptDoc.DataDefinition.ParameterFields

            strDateRange = "From " & dtFromDate.Date & " to " & dtToDate.Date
            paramField1 = paramFields.Item("DateRange")
            paramValues = paramField1.CurrentValues
            DiscreteVal = New ParameterDiscreteValue
            DiscreteVal.Value = strDateRange
            paramValues.Add(DiscreteVal)
            paramField1.ApplyCurrentValues(paramValues)

            Dim FromDate As String = Format(dtFromDate, "yyyyMMdd")
            strFromDate = FromDate
            paramField2 = paramFields.Item("FromDate")
            paramValues = paramField2.CurrentValues
            DiscreteVal = New ParameterDiscreteValue
            DiscreteVal.Value = strFromDate
            paramValues.Add(DiscreteVal)
            paramField2.ApplyCurrentValues(paramValues)

            Dim ToDate As String = Format(dtToDate, "yyyyMMdd")
            strToDate = ToDate

            paramField3 = paramFields.Item("ToDate")
            paramValues = paramField3.CurrentValues
            DiscreteVal = New ParameterDiscreteValue
            DiscreteVal.Value = strToDate
            paramValues.Add(DiscreteVal)
            paramField3.ApplyCurrentValues(paramValues)

            paramField4 = paramFields.Item("Locs")
            paramValues = paramField4.CurrentValues
            Select Case ddlReport.SelectedValue
                Case 106
                    bAll = False
                    iCnt = 0
                    For Each item As ListItem In lbLocs.Items
                        If item.Value = -1 Then
                            If item.Selected Then
                                bAll = True
                            End If
                        Else
                            If bAll = True Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            Else
                                If item.Selected Then
                                    If iCnt = 0 Then
                                        iCnt = 1
                                    End If
                                    DiscreteVal = New ParameterDiscreteValue
                                    DiscreteVal.Value = item.Value
                                    paramValues.Add(DiscreteVal)
                                End If
                            End If
                        End If
                    Next
            End Select
            paramField4.ApplyCurrentValues(paramValues)

            paramField5 = paramFields.Item("Agents")
            paramValues = paramField5.CurrentValues
            Select Case ddlReport.SelectedValue
                Case 106
                    bAll = False
                    iCnt = 0
                    For Each item As ListItem In lbAgents.Items
                        If item.Value.ToString = "-1" Then
                            If item.Selected Then
                                bAll = True
                            End If
                        Else
                            If bAll = True Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            Else
                                If item.Selected Then
                                    If iCnt = 0 Then
                                        iCnt = 1
                                    End If
                                    DiscreteVal = New ParameterDiscreteValue
                                    DiscreteVal.Value = item.Value
                                    paramValues.Add(DiscreteVal)
                                End If
                            End If
                        End If
                    Next
            End Select
            paramField5.ApplyCurrentValues(paramValues)

            paramField6 = paramFields.Item("Status")
            paramValues = paramField6.CurrentValues
            Select Case ddlReport.SelectedValue
                Case 106
                    bAll = False
                    iCnt = 0
                    For Each item As ListItem In lbStatus.Items
                        If item.Value.ToString = "-1" Then
                            If item.Selected Then
                                bAll = True
                            End If
                        Else
                            If bAll = True Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            Else
                                If item.Selected Then
                                    If iCnt = 0 Then
                                        iCnt = 1
                                    End If
                                    DiscreteVal = New ParameterDiscreteValue
                                    DiscreteVal.Value = item.Value
                                    paramValues.Add(DiscreteVal)
                                End If
                            End If
                        End If
                    Next
            End Select
            paramField6.ApplyCurrentValues(paramValues)

            paramField7 = paramFields.Item("LeadType")
            paramValues = paramField7.CurrentValues
            Select Case ddlReport.SelectedValue
                Case 106
                    bAll = False
                    iCnt = 0
                    For Each item As ListItem In lbLeadType.Items
                        If item.Value.ToString = "-1" Then
                            If item.Selected Then
                                bAll = True
                            End If
                        Else
                            If bAll = True Then
                                If iCnt = 0 Then
                                    iCnt = 1
                                End If
                                DiscreteVal = New ParameterDiscreteValue
                                DiscreteVal.Value = item.Value
                                paramValues.Add(DiscreteVal)
                            Else
                                If item.Selected Then
                                    If iCnt = 0 Then
                                        iCnt = 1
                                    End If
                                    DiscreteVal = New ParameterDiscreteValue
                                    DiscreteVal.Value = item.Value
                                    paramValues.Add(DiscreteVal)
                                End If
                            End If
                        End If
                    Next
            End Select
            paramField7.ApplyCurrentValues(paramValues)


            'Set DataBase Login Info
            rptDoc.SetDatabaseLogon(crUser, crPwd, crServer, crDatabase)

            ' Set the Crytal Report Viewer control's source to the report document
            crvReports.ReportSource = rptDoc

            'Provide Parameter Values
            crvReports.EnableParameterPrompt = False
            crvReports.DisplayGroupTree = False

            crvReports.RefreshReport()

            rptValues.Visible = False
            rptViewer.Visible = True
        End Sub


Thanks for your help in advance!!
Eddi Rae
Tags: Visual Basic, CrystalReports

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900