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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Public Class TypeDeProduit
'Déclaration de la variable pour la connection
Private cnx As OleDbConnection
'Déclaration de la variable pour la commande
Private cmd As OleDbCommand
'Déclaration de la variable pour le dataadapter
Private dta As OleDbDataAdapter
'Déclaration de la variable pour le dataset
Private dts As New DataSet
'Déclaration de la variable pour la requête
Private sql As String
'Déclaration de la variable pour la datatable
Private dtt As DataTable
'Déclaration de la variable pour le datarow
Private dtr As DataRow
'Déclaration de la variable pour le Nº de l'enregistrement
Private rownum As Integer
'Déclaration de la variable pour la connectionstring
Private cnxstr As String
'Déclaration de la variable pour le commandbuilder
Private cmdb As OleDbCommandBuilder
Private Sub TypeDeProduit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'ouverture de la connection (à partir du répertoire de l'application) sur la même ligne
cnxstr = "provider = microsoft.ace.oledb.12.0 ; data source = C:\Users\mto\Desktop\MINI-ERP\ERP.accdb;"
cnx = New OleDbConnection
cnx.ConnectionString = cnxstr
cnx.Open()
'Création de la requête sql
sql = "select TypeDeProduit.Type_de_produit from TypeDeProduit"
'Création de la commande et on l'instancie (sql)
cmd = New OleDbCommand(sql)
'Création du dataadapter (dta) et on l'instancie (cmd)
dta = New OleDbDataAdapter(cmd)
'On instancie la commande (cmd) à la connection (cnx)
cmd.Connection() = cnx
'On charge le dataset (dts) grâce à la propriété fill du dataadapter (dta)
dta.Fill(dts, "Type_de_produit")
'On charge la datatable (dtt) grâce à la propriété tables du dataset (dts)
dtt = dts.Tables("Type_de_produit")
DataGridView1.DataSource = dts
DataGridView1.DataMember = dtt.ToString
DataGridView1.Columns("Type_de_produit").Width = 190
End Sub
Private Sub Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fermer.Click
Me.Close()
End Sub
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
dts.Clear()
dta = New OleDbDataAdapter("SELECT TypeDeProduit.Type_de_produit FROM TypeDeProduit", cnx)
dta.Fill(dts, "Type_de_produit")
dtr = dts.Tables("Type_de_produit").NewRow
dtr(0) = Me.TextBox1.Text
MessageBox.Show("Bien ajouté")
dts.Tables("Type_de_produit").Rows.Add(dtr)
DataGridView1.DataSource = dts
DataGridView1.DataMember = dts.Tables("Type_de_produit").ToString
cmdb = New OleDbCommandBuilder(dta)
dta.Update(dts, "Type_de_produit")
Me.TextBox1.Text = String.Empty
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dtr = dts.Tables("Type_de_produit").NewRow
dts.Tables("Type_de_produit").Rows.Add(dtr)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each row As DataGridViewRow In DataGridView1.SelectedRows
DataGridView1.Rows.Remove(row)
Next
End Sub
End Class |
Partager