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
| Private Sub Text2_Click()
Dim obj_Connection, obj_Command, str_ConnectionString, str_SQL
'définir la chaîne de connexion
str_ConnectionString = "DSN=MA_BD;UID=;PWD=;"
'définir la requête
str_SQL = "INSERT INTO TABLE1 (COL1, col2) VALUES ('CHAINE11', 'CHAINE21');"
'Création et paramétrage de la connexion à la BD
Set obj_Connection = CreateObject("ADODB.Connection")
obj_Connection.ConnectionString = str_ConnectionString
'Ouvrir la connexion
obj_Connection.Open
'Création et paramétrage de la commande
Set obj_Command = CreateObject("ADODB.Command")
obj_Command.ActiveConnection = obj_Connection
obj_Command.CommandText = str_SQL
obj_Command.Execute 'Exécuter la commande
Set obj_Command = Nothing
obj_Connection.Close 'Fermer la connexion
Set obj_Connection = Nothing
End Sub |
Partager