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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| Private Sub CommandButton1_Click()
'Déclaration de variable
Dim cnn As New ADODB.Connection, rst As New ADODB.Recordset
Dim MaCommand As ADODB.Command
Dim Ligne As Integer
Dim champ_1 As String
Dim champ_2 As String
Dim champ_3 As String
Dim champ_4 As String
Dim champ_5 As String
'effacement des anciennes donées
Range(Cells(1, 2), Cells(65536, 6)).Select
Selection.ClearContents
Cells(1, 1).Select
' Ouverture de la connexion à la base de donnée
'cnn.Open "ODBC;DATABASE=test;DSN=easyphp;UID=root"
cnn.Open "ODBC;DATABASE=peofofo;DSN=serveur_peofofo;UID=root"
'appel de la requète SQL Semaine
Text_SQL = "SELECT champ_1, champ_2, champ_3, champ_4, champ_5 FROM essai_table"
rst.Open Text_SQL, cnn, adOpenForwardOnly, adLockReadOnly
If Not (rst.EOF And rst.BOF) Then
rst.MoveFirst
Ligne = 1
While Not (rst.EOF)
For i = 0 To 4
Cells(Ligne, 2 + i).Value = rst.Fields(i).Value
Next i
Ligne = Ligne + 1
rst.MoveNext
Wend
End If
rst.Close 'Fermeture de la requète
cnn.Close 'Fermeture de la connection
End Sub
Private Sub CommandButton2_Click()
'Déclaration de variable
Dim cnn As New ADODB.Connection, rst As New ADODB.Recordset
Dim MaCommand As ADODB.Command
Dim champ_1 As Double
Dim champ_2 As String
Dim champ_3 As String
Dim champ_4 As String
Dim champ_5 As String
' Ouverture de la connexion à la base de donnée
'cnn.Open "ODBC;DATABASE=test;DSN=easyphp;UID=root"
cnn.Open "ODBC;DATABASE=peofofo;DSN=serveur_peofofo;UID=root"
champ_1 = Cells(1, 8).Value
champ_2 = Cells(1, 9).Value
champ_3 = Cells(1, 10).Value
champ_4 = Cells(1, 11).Value
champ_5 = Cells(1, 12).Value
'Requète pour insérer une ligne de commande
Text_SQL = "INSERT INTO essai_table VALUES (null," & champ_1 & " ," & champ_2 & ", " & champ_3 & ", " & champ_4 & " ," & champ_5 & ")"
rst.Open Text_SQL, cnn, adOpenForwardOnly, adLockReadOnly
cnn.Close 'Fermeture de la connection à la base de donnée
End Sub |