First you have to importing the folowing namespaces up to the Public Class FormX:
In the form load event of the form which contains the crystal report viewer type the folowing code:Code:Imports CrystalDecisions.Shared Imports CrystalDecisions.CrystalReports Imports CrystalDecisions.CrystalReports.Engine
Good luckCode:Dim MyReport As New MyReportName Dim ServerName As String = "MyDataSource" Dim UserID As String = "MyUserID" Dim Password As String = "MyUserPassword" Dim DatabaseName As String = "MyDataBaseName" Dim rptTable As CrystalDecisions.CrystalReports.Engine.Table Dim rptLogIn As TableLogOnInfo = New CrystalDecisions.Shared.TableLogOnInfo MyReport.SetDatabaseLogon(UserID, Password, ServerName, DatabaseName) For Each rptTable In MyReport.Database.Tables rptLogIn = rptTable.LogOnInfo rptLogIn.ConnectionInfo.ServerName = ServerName rptLogIn.ConnectionInfo.DatabaseName = DatabaseName rptLogIn.ConnectionInfo.UserID = UserID rptLogIn.ConnectionInfo.Password = Password rptTable.ApplyLogOnInfo(rptLogIn) Next MyReport.Refresh() MyCrystalReportViewer.ReportSource = MyReport MyCrystalReportViewer.Show()![]()




Reply With Quote