Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
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?
Posted
Comments
Al Moje 18-Oct-11 22:30pm    
Hi,
Try to use datasets. Store filter records in your dataset, and if you have sub report link records by its primary key...

In the report I have made now I used selectcommands like:

SELECT column1, column2, column3 FROM Order WHERE OrderID = {?OrderID}
And set the parameter to OrderID to be able to change this at runtime.

Is it possible to get the same result with the filters?
 
Share this answer
 
I have now tried to use dataset as primary source from database, I have filtered the data based on f-ex OrderID I still use the code above to set the dataspource and now I get data in my report if I change the database but if I set another OrderID than 1 I get no data..how come?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900