Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Issue when trying to change database dynamicly Post Reply Post New Topic
Author Message
johmolan
Newbie
Newbie


Joined: 16 Oct 2011
Location: Norway
Online Status: Offline
Posts: 2
Quote johmolan Replybullet Topic: Issue when trying to change database dynamicly
    Posted: 16 Oct 2011 at 11:42pm
I have a report made in vs2008, it is a main report with 9 sub-reports. all the sub-reports have parameters. 1 uses KundeID and the rest uses OrdreID. I hva linked the parametres in the subreports to parameters in the main report this way it only prompts for the 2 parameters when I run the report in crystalreportviewer using this code:

Dim crp As New CrystalReport3 Me.CrystalReportViewer1.ReportSource = crp

But when I try to change the logoninfo dynamicly and set the parameters from the vb-code it only prompts for the KundeID and it ordredoes so several times, byt is does not prompt for the OrdreID parameter and no data is shown in the subreports using this parameter.

My code lookd like this:

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

cryRpt.Load("Reports/CrystalReport5.rpt") '***************************************************************
'Dim Sname As String
'Dim Dbname As String
'Dim Uname As String
'Dim Pwd As String 'Dim kid As Integer = 2
'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("KundeID")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = 1
crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
'End parameter

' Begin parameter
crParameterFieldDefinition = crParameterFieldDefinitions.Item("OrdreID")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = 1 crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
' End parameter CrTables = cryRpt.Database.Tables

For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next

CrystalReportViewer1.ReportSource = cryRpt

'*************************************************************************** '*************************************************************************** '******************************************************************************
End Sub
End Class



I also tried to put the parameter chang code into the For loop but then I got an error that this changes can not be applied to a linked parameter.

Can anyone help me??
IP IP Logged
CsharpCoding
Newbie
Newbie


Joined: 26 Jan 2012
Location: Netherlands
Online Status: Offline
Posts: 4
Quote CsharpCoding Replybullet Posted: 17 Feb 2012 at 10:22am
you have to link the subreports tables to the datasource to
 
// please convert C# to VB yourself

// link the tables for the subreports

           

CrystalDecisions.Shared.TableLogOnInfo currentTableLogOn;

CrystalDecisions.Shared.ConnectionInfo cnCurrentConnectInfo;

// set here the connection parameters
 
foreach(CystalDecisions.CrystalReports.Engine.ReportDocument subReport in crReport.Subreports)

{

    foreach (CrystalDecisions.CrystalReports.Engine.Table reportTable in subReport.Database.Tables)

    {

       currentTableLogOn = reportTable.LogOnInfo;

       currentTableLogOn.ConnectionInfo = cnCurrentConnectInfo;

       reportTable.ApplyLogOnInfo(currentTableLogOn);

      }

}



Edited by CsharpCoding - 17 Feb 2012 at 10:29am
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.