Private Sub setConn(ByRef rpt As CrystalDecisions.CrystalReports.Engine.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 crReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument = rpt
With crConnectionInfo
.ServerName = "servername"
.DatabaseName = "dbaname"
.UserID = "username"
.Password = "password"
End With
CrTables = rpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
If LCase(CrTable.Location) = "command" Then
Exit For
End If
CrTable.Location = "databasename.dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
Next
End Sub
hope this will help.
UPDATE SM: Added pre tags. Though Answer looks fine but would had been complete if replier adds some explanation to what code has been posted/what was the enquirer missing. :thumbsup:
From HS:
from where u r calling report there u need to declare 1 variable like this
ByVal rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument
after that follow all the steps u were doing but before dat call my cade which i have given to u like this
setConn(rpt)
it will make all the connection to ur report with table.
Just try it.
I am damn sure it will work. coz for ma all the projects its working.
best luck