myGoogleResults

Tuesday, January 22, 2008

Crystal Reports changing logon infomation

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

' this is the class for connecting crystal reports to database
' applies logoninfo

Public Class Creports

'returns a ReportDocument after applying logoninfo for the passed report
Public Function connect(ByVal rpt5 As ReportDocument) As ReportDocument

Dim tbCurrent As Table
Dim tbLogOnInfo As TableLogOnInfo

Try
'apply LogOn info for each table of the report document
For Each tbCurrent In rpt5.Database.Tables
tbLogOnInfo = tbCurrent.LogOnInfo

With tbLogOnInfo.ConnectionInfo
.ServerName = mod_1.serverName
.UserID = mod_1.userName
.Password = mod_1.password
.DatabaseName = mod_1.dataBaseName
End With

tbCurrent.ApplyLogOnInfo(tbLogOnInfo)
'tbLogOnInfo = tbCurrent.LogOnInfo
'tbLogOnInfo.ConnectionInfo.ServerName = serverName
'tbLogOnInfo.ConnectionInfo.UserID = userName
'tbLogOnInfo.ConnectionInfo.Password = password
'tbLogOnInfo.ConnectionInfo.DatabaseName = databaseName
'tbCurrent.ApplyLogOnInfo(tbLogOnInfo)
Next tbCurrent

Return rpt5

Catch lsExp As LoadSaveReportException
MessageBox.Show(lsExp.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Function

End Class

1 comment:

Sudesh said...

Parameter passing to a crystal report.

Dim pvCollection As New ParameterValues
Dim pvYCollection As New ParameterValues

Dim pdvMonthly As New ParameterDiscreteValue
Dim pdvYMonthly As New ParameterDiscreteValue

mod_1.reportO.Load("../reports/crpMonAge.rpt") 'Load Report
mod_1.reportO = mod_1.reportDoc.connect(reportO) 'Apply LogonInfo

pdvMonthly.Value = cbMonth.SelectedIndex + 1 'Get Parameters from form
pdvYMonthly.Value = CInt(cmbYear.Text)

pvCollection.Add(pdvMonthly) 'Pass Month
mod_1.reportO.DataDefinition.ParameterFields("paraMonth").ApplyCurrentValues(pvCollection)

pvYCollection.Add(pdvYMonthly) 'Pass Year
mod_1.reportO.DataDefinition.ParameterFields("paraYear").ApplyCurrentValues(pvYCollection)

Me.CrystalReportViewer1.ReportSource = reportO