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
| Option Explicit
Public oConnect As ADODB.Connection
Private Sub ConnectionDB()
Dim S As String
Set oConnect = New ADODB.Connection
S = "DRIVER={MySQL ODBC 5.1 Driver};" & _
"SERVER=" & Sheets("config").Range("B1").Text & ";" & _
"DATABASE=" & Sheets("config").Range("B2").Text & ";" & _
"USER=" & Sheets("config").Range("B3").Text & ";" & _
"PASSWORD=" & Sheets("config").Range("B4").Text & ";" & _
"Option=3"
oConnect.Open S
End Sub
Sub MySQLInsertData()
Dim Rs As ADODB.Recordset
Dim Derligne As Integer, i As Integer
Dim Requete As String
Set Rs = New ADODB.Recordset
Call ConnectionDB
With Sheets(1)
Derligne = .Range("A65000").End(xlUp).Row
For i = 2 To Derligne
Requete = "INSERT INTO employes_tbl(ID_EMP, NOM, PRENOM, ADRESSE, VILLE, PAYS, TEL, EMAIL) VALUES(" & .Cells(i, 1) & ", '" & .Cells(i, 2) & "', '" & .Cells(i, 3) & "', " & .Cells(i, 4) & "', " & _
.Cells(i, 5) & "', " & .Cells(i, 6) & "', " & .Cells(i, 7) & ", '" & .Cells(i, 8) & ")'"
Rs.Open Requete, oConnect, adOpenDynamic, adLockOptimistic
Next i
End With
oConnect.Close
Set Rs = Nothing
End Sub |
Partager