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 100 101 102 103 104
| Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Public Class agent
Dim ObjetConnection As OleDbConnection
Dim ObjetCommand As OleDbCommand
Dim ObjetDataAdapter As OleDbDataAdapter
Dim ObjetDataSet As New DataSet()
Dim strSql As String
Dim datareader As OleDbDataReader
Dim lire As OleDbDataReader
Dim ObjetDataTable As DataTable
Dim ObjetDataRow As DataRow
Dim RowNumber As Integer
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\appel.accdb"
Dim ObjetCommandBuilder As OleDbCommandBuilder
Private Sub agent_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'chargement du combobox
strSql = " SELECT idserv from service"
ObjetConnection = New OleDbConnection()
ObjetConnection.ConnectionString = strConn
Try
ObjetConnection.Open()
ObjetCommand = New OleDbCommand(strSql, ObjetConnection)
lire = ObjetCommand.ExecuteReader
Do While lire.Read()
cmb_service.Items.Add(lire("idserv"))
Loop
lire.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString(), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btn_enrg.Click
strSql = "SELECT idagent, nom, prenom, fonction, contact, mail, habite, idserv FROM agent"
Dim ObjetConnection As OleDbConnection = New OleDbConnection()
ObjetConnection.ConnectionString = strConn
ObjetConnection.Open()
Dim ObjetCommand As OleDbCommand = New OleDbCommand(strSql)
ObjetDataAdapter = New OleDbDataAdapter(ObjetCommand)
ObjetCommand.Connection() = ObjetConnection
ObjetDataAdapter.Fill(ObjetDataSet, "FON_DATA")
ObjetDataTable = ObjetDataSet.Tables("FON_DATA")
ObjetDataRow = ObjetDataSet.Tables("FON_DATA").NewRow()
ObjetDataRow("idagent") = Me.txt_matricule.Text
ObjetDataRow("nom") = Me.txt_nom.Text
ObjetDataRow("prenom") = Me.txt_prenom.Text
ObjetDataRow("fonction") = Me.txt_fonction.Text
ObjetDataRow("contact") = Me.txt_contact.Text
ObjetDataRow("mail") = Me.txt_mail.Text
ObjetDataRow("habite") = Me.txt_habite.Text
ObjetDataRow("idserv") = Me.cmb_service.SelectedItem
ObjetDataSet.Tables("FON_DATA").Rows.Add(ObjetDataRow)
ObjetCommandBuilder = New OleDbCommandBuilder(ObjetDataAdapter)
ObjetDataAdapter.Update(ObjetDataSet, "FON_DATA")
'Afficher le contenu d'un textbox dans un DataGridView1
DataGridView1.DataSource = ObjetDataSet.Tables("FON_DATA")
DataGridView1.Refresh() ' faire la mise à jour du DataGridView1
MsgBox("Enregistrement effectué", MsgBoxStyle.Information)
ObjetDataSet.Clear()
ObjetDataAdapter.Fill(ObjetDataSet, "FON_DATA")
ObjetDataTable = ObjetDataSet.Tables("FON_DATA")
ObjetConnection.Close()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub btn_modifier_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_nouveaau.Click
Me.txt_matricule.Text = ""
Me.txt_nom.Text = ""
Me.txt_prenom.Text = ""
Me.txt_fonction.Text = ""
Me.txt_contact.Text = ""
Me.txt_mail.Text = ""
Me.txt_habite.Text = ""
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub OleDbDataAdapter1_RowUpdated(sender As Object, e As OleDbRowUpdatedEventArgs) Handles OleDbDataAdapter1.RowUpdated
End Sub
End Class |
Partager