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