要設置多個數據庫的憑據,使用下面的代碼
Dim Report1 As New CrystalReport1
Dim i As Integer
For i = 0 To Report1.DataSourceConnections.Count - 1
Dim AccessDBFileName As String = IO.Path.GetFileName(Report1.DataSourceConnections.Item(i).ServerName)
Dim Password As String = ""
Select Case AccessDBFileName
Case "Database1.mdb"
Password = "Password1"
Case "Database2.mdb"
Password = "Password2"
Case "Database3.mdb"
Password = "Password3"
Case "Database4.mdb"
Password = "Password4"
End Select
Report1.DataSourceConnections.Item(i).SetLogon("", Password)
Next
的用GetFileName函數從Access文件的路徑檢索數據庫文件名。
檢查以下鏈接。 http://stackoverflow.com/questions/6112997/why-does-crystal-report-viewer-always-asks-for-login-details-to-access-database http://stackoverflow.com/questions/ 14459966/crystal-report-always-asks-for-database-login –
感謝David先生,但我已經知道如何傳遞登錄信息。我想知道的是如何在多個數據庫中執行相同的操作。 –