1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
Sub Connection_Oracle2()
'Déclaration de la variable de connexion
Dim cNx As ADODB.Connection, oRS As ADODB.Recordset
Dim NomDuDSN As String, NomUtilisateur As String, MotDePasse As String, sSQL As String
NomDuDSN = "XxX"
NomUtilisateur = "XxX"
MotDePasse = "XxX"
Set cNx = New ADODB.Connection
'Définition de la chaîne de connexion
cNx.ConnectionString = "DSN=" & NomDuDSN & ";UID=" & NomUtilisateur & ";PWD=" & MotDePasse & ";"
cNx.Open
sSQL = "SELECT trade_id FROM trade ;"
Set oRS = New ADODB.Recordset
oRS.Open sSQL, cNx, adOpenStatic
MsgBox IIf(oRS.EOF, "Il n'y a aucun enregistrement", "Il y a au moins un enregistrement")
With ThisWorkbook.Worksheets("Feuil1")
.UsedRange.ClearContents
.Range("A1").CopyFromRecordset oRS
End With
oRS.Close
cNx.Close
Set oRS = Nothing
Set cNx = Nothing
End Sub |