I have made a crystal report with subreports,
In my subreports I have added commands like:
SELECT * FROM Orders where orederID = {?orderID}

When I run the report in viewer the report prompts for the orderID with a dialogbox.
But I have several subreports that requires the same orderID it prompt for the value for every subreport. Is there a way to make the report get the ordreID once and reuse it for each subreport without the need for the prompt, ogr is it a way to do it in code?

6 Years
Discussion Span
Last Post by johmolan

Iam not sure what exactly you want, but you can create a class variable (type of integer) and when you get the 1st for the 1s time, asign this id to this class variable. And later simply use it.

If its not in any help, please provide us some code. It will be easier for us.
thx in advance.


I solved this by adding a parameter to the main report and link the sub-reports to this parameter.


The next issue is that I need to be able to connect to a remote database as well to make a report or just to be able to connect to a different database.

I have searched the internet for help on this issue, and found some code-snips that I have tried out. the code looks like this.

Collapse | Copy Code
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Configuration


Public Class CR
    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

        Dim Sname As String
        Dim Dbname As String
        Dim Uname As String
        Dim Pwd As String
        Dim kid As Integer = 1
        Dim oid As Integer = 1
        Sname = CRdb.Servadr
        Dbname = CRdb.Servname
        Uname = CRdb.Username
        Pwd = CRdb.Passw
        MsgBox("Sname = " & Sname)
        MsgBox("Dbname = " & Dbname)
        MsgBox("Uname = " & Uname)
        MsgBox("Pwd = " & Pwd)
        With crConnectionInfo
            .ServerName = "JOHNMOLANDS-PC\SQLEXPRESS"
            .DatabaseName = "Kalkyle1"
            .UserID = "User2"
            .Password = "user2"
        End With
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As ParameterValues
        Dim crParameterDiscreteValue As ParameterDiscreteValue
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
        ' Begin parameter
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("1")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterDiscreteValue = New ParameterDiscreteValue
        crParameterDiscreteValue.Value = kid
        ' End parameter

        Dim crParameterFieldDefinitions2 As ParameterFieldDefinitions
        Dim crParameterFieldDefinition2 As ParameterFieldDefinition
        Dim crParameterValues2 As ParameterValues
        Dim crParameterDiscreteValue2 As ParameterDiscreteValue

        crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields
        ' Begin parameter
        crParameterFieldDefinition2 = crParameterFieldDefinitions2.Item("2")
        crParameterValues2 = crParameterFieldDefinition2.CurrentValues
        crParameterDiscreteValue2 = New ParameterDiscreteValue
        crParameterDiscreteValue2.Value = oid
        ' End parameter


        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo


        CrystalReportViewer1.ReportSource = cryRpt
End Sub
End Class

But when I run this code, the report asks for the first parameter over and over and over again for all subreports but never for the second parameter, then in the end when the report loads all the data linked to the second parameter is missing.

Why is that? I do not get promted for any logon info so I guess that part is working but somewhere along the way something goes wrong and the parameter links does not work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.