Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Public Sub SetLogonInfo(ByRef objrpt As ReportDocument)
Dim connection As IConnectionInfo
Dim newServerName As String = "dbServer"
Dim newDatabaseName As String = "dbName"
Dim userID As String = "dbusername"
Dim password As String = "dbpassword"
' Change the server name and database in main reports
For Each connection In objrpt.DataSourceConnections
' SetConnection can also be used to set
' new logon and new database table
objrpt.DataSourceConnections(connection.ServerName, _
connection.DatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
Next
' Change the server name and database in subreports
Dim subreport As ReportDocument
For Each subreport In objrpt.Subreports
For Each connection In subreport.DataSourceConnections
' SetConnection can also be used to set
' new logon and new database table
subreport.DataSourceConnections(connection.ServerName, _
connection.DatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
Next
Next
End Sub
Public Sub SetParameterValue(ByRef objRPT As ReportDocument, _
ByVal parameterName As String, _
ByVal ParameterValue As String)
Dim parameterField As ParameterField
parameterField = objRPT.ParameterFields(parameterName)
parameterField.CurrentValues.AddValue(ParameterValue)
parameterField.HasCurrentValue = True
End Sub
No comments:
Post a Comment