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

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
Posted 23-Jan-11 8:39am
The.Z459
Edited 23-Jan-11 8:40am
v2
Comments
Prerak Patel at 24-Jan-11 4:35am
   
What is the filter condition in report?!
The.Z at 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..
 
`Thanks,
Z
Prerak Patel at 24-Jan-11 8:29am
   
Have you tried putting your parameters on the report? Are they passed fine?!
The.Z at 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
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 23 Jan 2011
Copyright © CodeProject, 1999-2014
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