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
| Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class Affecter
Dim con As New MySqlConnection
Dim constr As String = "server=localhost;" _
& "user id=root;" _
& "password=;" _
& "database=intervention"
Dim de As MySqlDataAdapter
Dim dsp As New DataSet
Private Sub Affecter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'pour ma combobox PAS DE SOUCIS
Try
con.ConnectionString = constr
con.Open()
Catch ex As MySqlException
MsgBox(ex.Message)
End Try
Dim sStmt As String = "SELECT id, nom, prenom FROM agents"
Dim cmd As New MySqlCommand(sStmt, con)
Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
Dim dt As New DataTable("agents")
da.Fill(dt)
If dt.Rows.Count > 0 Then
ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "nom" 'What is displayed
ComboBox1.ValueMember = "id" 'The ID of the row
End If
'pour mon DATAGRIDVIEW rien ne s'affiche pourtant la requete est bonne
de = New MySqlDataAdapter("SELECT * FROM affectations", con)
de.Fill(dsp, "affectations")
DataGridView1.DataSource = dsp.Tables("affectations")
DataGridView1.Columns("id").Visible = False
DataGridView1.Columns("vehicule").Visible = False
DataGridView1.Columns("fonction").Visible = False
DataGridView1.Columns("personne").HeaderText = "Nom"
DataGridView1.Columns(5).Width = 150 'nom
DataGridView1.Columns("heure_deb").HeaderText = "Heure de Début"
DataGridView1.Columns(1).Width = 100 'prenom
DataGridView1.Columns("heure_fin").HeaderText = "Heure de Fin"
DataGridView1.Columns(2).Width = 210 'fonction
DataGridView1.AllowUserToAddRows = False
DataGridView1.RowHeadersVisible = False
End Sub |
Partager