problems with getting data from database to report

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have a REPORT WITH 10 SUBREPORTS, I have 2 Parameters in the main report and links the subreports to these parameters.
My code looks like this:

VB.NET:
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Configuration
 

 
Public Class CR
    Public Sname As String
    Public Dbname As String
    Public Uname As String
    Public Pwd As String
    Public kid As Integer
    Public oid As Integer
 

    Private _passedText(180) As String
 
    Public Property [PassedText]() As String()
        Get
            Return _passedText
        End Get
        Set(ByVal Value As String())
            _passedText = Value
        End Set
    End Property
 

 
    Private Sub CR_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table
 
        cryRpt.Load("Reports/CrystalReport5.rpt")
        '***************************************************************
    
 
       
 
        Dim conn = New SqlClient.SqlConnection
        conn = New SqlConnection(Form1.DS2)
 

        Dim crParameterDiscreteValue As ParameterDiscreteValue
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldLocation As ParameterFieldDefinition
        Dim crParameterValues As ParameterValues
 
        '
        ' Get the report parameters collection.
        '
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
 
        conn.Open()
 
        With crConnectionInfo
            .ServerName = Sname
            .DatabaseName = Dbname
            .UserID = Uname
            .Password = Pwd
        End With
 

        '
        ' Get the report parameters collection.
        '
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
 

        ' Add a parameter value - START
        crParameterFieldLocation = crParameterFieldDefinitions.Item("KundeID")
        crParameterValues = crParameterFieldLocation.CurrentValues
        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
        crParameterDiscreteValue.Value = kid
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
        ' Add a parameter value - END

 
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
 

        crParameterFieldLocation = crParameterFieldDefinitions.Item("OrdreID")
        crParameterValues = crParameterFieldLocation.CurrentValues
        crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
        crParameterDiscreteValue.Value = oid
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
 
        
 
        CrTables = cryRpt.Database.Tables
        ' 
        For Each CrTable In CrTables
            Try
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
 

            Catch ex As Exception
                MessageBox.Show("Reason for error:" & ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
 

            End Try
 
        Next
        CrystalReportViewer1.ReportSource = cryRpt
        conn.Close()
 

    End Sub


I have made the report based on a database called "kalkyle1" and when I run the report using this report it works great. But I made a copy of this database and called it "kalkyle2". When I run the report based on this report somehow I only gets the data to the subreports using the 1st parameter and not the others using parameter 2. anyone who has any idea what I am doing wrong?
 
Back
Top