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
|
Dim result As Boolean = False
Dim data_base_engine As New DBEngine
Dim data_base As Database
Dim nom_fichier As String 'nom du fichier d'enregistrement de la simulation
nom_fichier = InputBox("Sous quel nom voulez vous enregistrer votre simulation ?", "Enregistrer sous")
If nom_fichier = "" Then Exit Sub 'signifie que l'utilisateur a annulé l'action
nom_fichier = nom_fichier & ".mdb"
Try
data_base = data_base_engine.CreateDatabase("d:\temp\" & nom_fichier, dbLangGeneral)
If Not (data_base Is Nothing) Then result = True
Catch ex As Exception : MsgBox(ex.Message)
Finally : If Not (data_base Is Nothing) Then data_base.Close()
End Try
'Déclarer la connexion
Dim ObjetConnection As OleDbConnection
' Déclaration l'Objet Commande
Dim ObjetCommand As OleDbCommand
'Paramètres de connexion à la Base de données
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= d:\temp\" & nom_fichier & ";"
ObjetConnection = New OleDbConnection
'Donner à la propriété ConnectionString les paramètres de connexion
ObjetConnection.ConnectionString = strConn
'Ouvrir la connexion
ObjetConnection.Open()
'Instancier un objet Commande
ObjetCommand = New OleDbCommand
'Lier Commande et Connexion
ObjetCommand.Connection = ObjetConnection
'Indiquer le type de commande
ObjetCommand.CommandType = CommandType.Text
'Donner le texte de la commande SQL
'Ici on crée une table Simulation
ObjetCommand.CommandText = "CREATE TABLE Simulation (Sim_ID INTEGER NOT NULL PRIMARY KEY, Sim_Date DATETIME, Sim_1 CURRENCY, Sim_2 CURRENCY, Sim_3 CURRENCY, Sim_4 CURRENCY, Sim_5 CURRENCY, Sim_6 CURRENCY)" |
Partager