Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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

Thanks for your help in advance!!
Eddi Rae
Posted 11-Dec-12 2:55am
Comments
Sheikh Muhammad Haris at 15-Dec-12 10:39am
   
Can you specify the error you are having with above code ?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I found the issue. I had the dataset built incorrectly. Once I rebuilt it, everything worked properly.
Thanks for your response.
Eddi Rae
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 155
1 Mika Wendelius 151
2 Sergey Alexandrovich Kryukov 135
3 TheRealSteveJudge 114
4 Peter Leow 110
0 Sergey Alexandrovich Kryukov 8,613
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,456
4 Richard MacCutchan 2,442


Advertise | Privacy | Mobile
Web02 | 2.8.150123.1 | Last Updated 16 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100