Click here to Skip to main content
15,896,348 members

CrystalReports - Parameter from vb.net

The.Z asked:

Open original thread
Hi.
I am using the CrystalReportsViewer in my VB-project.
I have designed a simple report which is viewed perfectly in the viewer.

Now i want to add some parameter-values to filter my results.

Here is my code:


VB
Dim cryRpt As New ReportDocument
Dim crtableLogoninfos As New TableLogOnInfos
Dim crtableLogoninfo As New TableLogOnInfo
Dim crConnectionInfoTableEFI As New ConnectionInfo
Dim crConnectionInfoTableLeistungen As New ConnectionInfo
Dim CrTables As Tables
Dim CrTable As Table

// FORM - LOAD-Section
      cryRpt.Load(path)

        With crConnectionInfoTableEFI
            .ServerName = srv
            .DatabaseName = dbKunden
            .UserID = user
            .Password = pw
        End With

        With crConnectionInfoTableLeistungen
            .ServerName = srv
            .DatabaseName = dbLeistung
            .UserID = user
            .Password = pw
        End With

        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            If crtableLogoninfo.TableName = "Leistungen" Then
                crtableLogoninfo.ConnectionInfo = crConnectionInfoTableLeistungen
            ElseIf crtableLogoninfo.TableName = "debitoren" Then
                crtableLogoninfo.ConnectionInfo = crConnectionInfoTableEFI
            End If
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
//

Private Sub cmdOk_ButtonKlick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
      Dim crParameterFieldDefinitions As ParameterFieldDefinitions
      Dim crParameterFieldDefinition As ParameterFieldDefinition
      Dim crParameterValues As New ParameterValues
      Dim crParameterDiscreteValue As New ParameterDiscreteValue
      Dim from, to As Integer
      If txtVon.Text = String.Empty Then
          from = 0
      Else
          from = Convert.ToInt32(txtVon.Text)
      End If
      If txtBis.Text = String.Empty Then
          to = 9999999
      Else
          to = Convert.ToInt32(txtBis.Text)
      End If
      crParameterDiscreteValue.Value = Convert.ToInt32(from)
      crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
      crParameterFieldDefinition = crParameterFieldDefinitions.Item("Kundennummer_von")
      crParameterValues = crParameterFieldDefinition.CurrentValues
      crParameterValues.Clear()
      crParameterValues.Add(crParameterDiscreteValue)
      crParameterDiscreteValue = New ParameterDiscreteValue
      crParameterDiscreteValue.Value = Convert.ToInt32(to)
      crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
      crParameterFieldDefinition = crParameterFieldDefinitions.Item("Kundennummer_bis")
      crParameterValues = crParameterFieldDefinition.CurrentValues
      crParameterValues.Add(crParameterDiscreteValue)
      crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

      CrystalReportViewer1.ReportSource = cryRpt
      CrystalReportViewer1.Refresh()
  End Sub


The "Kundennummer_von" and the "Kundennummer_bis" are my, in the CrystalReport Defined Parameters.
The "Kundennummmer" (translation: Client-number) is an integer, defined in the database: max length is 7 digits.
The filter is working, but i have some bugs:
When I want to list only one client, i sometimes get 2...
example: from=2300125 ; to=2300125 --> I get the clients 2300121 AND 2300125
When I try to list the client 2300121, it works fine...
When I try to list client 1 to client 2... I get random clients...


What's wrong with my code??
Thanks,
Regards,
The.Z
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