本文介绍了获取错误:缺少参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB.net中使用Crystal的新手。我有多个参数。其中一些有多个值。我查看了几个网站,提供了有关如何将这些参数从vb.net传递到水晶报表查看器和报表的建议。以下是我的代码。我不确定它有什么不对。



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.

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





感谢你的帮助!!

Eddi Rae



Thanks for your help in advance!!
Eddi Rae

推荐答案



这篇关于获取错误:缺少参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:15