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
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'On crée une connexion
Dim chemin As String
chemin = "E:\Documents and Settings\M.Amine\Bureau\PFA.mdb"
Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & chemin)
'On crée notre commande contenant la requête SQL où l'on selectionne toute la table Table_cocktail
Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
Mycommand.CommandText = "SELECT PFA.* FROM PFA"
'On crée un DataAdapter (essentiel pour enregistrer notre dataSet dans la bdd)
Dim MyDataAdapter As New OleDbDataAdapter
MyDataAdapter = New OleDbDataAdapter(Mycommand)
Dim MyDataset As New DataSet()
Dim MyDataTable As DataTable
Dim MyDataRow As DataRow
MyConnexion.Open()
'Mycommand.ExecuteNonQuery()
'Avec l'aide de la propriété Fill du DataAdapter charger le DataSet
MyDataAdapter.Fill(MyDataset, "PFA")
'On met alors dans un Objet DataTable une table du DataSet
MyDataTable = MyDataset.Tables("PFA")
'On crée alors une nouvelle ligne
MyDataRow = MyDataset.Tables("PFA").NewRow()
'on lui implémente la valeur du champ
MyDataRow("Date de prise") = TextBox9.Text
MyDataRow("Mesure 1") = TextBox1.Text
MyDataRow("Mesure 2") = TextBox2.Text
MyDataRow("Mesure 3") = TextBox3.Text
MyDataRow("Mesure 4") = TextBox4.Text
MyDataRow("Mesure 5") = TextBox5.Text
MyDataRow("Moyenne") = TextBox6.Text
MyDataRow("Etendu") = TextBox8.Text
'ici on ajoute une ligne(row) à notre dataset
MyDataset.Tables("PFA").Rows.Add(MyDataRow)
'Pour modifier les valeurs changées dans le DataAdapter
Dim MyCommandBuilder As New OleDbCommandBuilder(MyDataAdapter)
'Et voila notre BDD mise à jour
Dim CmdBuild As New OleDb.OleDbCommandBuilder(MyDataAdapter)
MyDataAdapter.InsertCommand = CmdBuild.GetInsertCommand()
MyConnexion.Close()
'On vide le DataSet et on le 'recharge' de nouveau.
MyDataset.Clear()
MyDataAdapter.Update(MyDataset, "PFA")
MyDataTable = MyDataset.Tables("PFA")
End Sub |
Partager