Click here to Skip to main content
13,043,491 members (52,340 online)
Rate this:
Please Sign up or sign in to vote.
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:

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
        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
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
          from = Convert.ToInt32(txtVon.Text)
      End If
      If txtBis.Text = String.Empty Then
          to = 9999999
          to = Convert.ToInt32(txtBis.Text)
      End If
      crParameterDiscreteValue.Value = Convert.ToInt32(from)
      crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
      crParameterFieldDefinition = crParameterFieldDefinitions.Item("Kundennummer_von")
      crParameterValues = crParameterFieldDefinition.CurrentValues
      crParameterDiscreteValue = New ParameterDiscreteValue
      crParameterDiscreteValue.Value = Convert.ToInt32(to)
      crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
      crParameterFieldDefinition = crParameterFieldDefinitions.Item("Kundennummer_bis")
      crParameterValues = crParameterFieldDefinition.CurrentValues
      CrystalReportViewer1.ReportSource = cryRpt
  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??
Posted 23-Jan-11 7:39am
Updated 23-Jan-11 7:40am
Prerak Patel 24-Jan-11 4:35am
What is the filter condition in report?!
The.Z 24-Jan-11 6:50am
{Leistungen.Kundennr} in {?Kundennummer_von} to {?Kundennummer_bis}

Where "Leistungen" is the database-table and Kundennr the Client-Number,
Kundennummer_von / Kundennummer_bis are the parameters..

Prerak Patel 24-Jan-11 8:29am
Have you tried putting your parameters on the report? Are they passed fine?!
The.Z 24-Jan-11 9:12am
yes... I tryed it with CrystalReports XI...
They where parsed fine... (it works in CR XI)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 23 Jan 2011
Copyright © CodeProject, 1999-2017
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