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
| Dim i As String
Dim y As Integer = -1
Cnx()
If Connexion.State <> 1 Then
MessageBox.Show("La connexion au serveur n'a pas été réalisée")
Else
strRequete = "SELECT NomSociete, NomEmploye, S.idSociete FROM Societes S, Employes E WHERE S.idSociete = E.idSociete " & _
"GROUP BY NomSociete, NomEmploye, S.idSociete ORDER BY NomSociete "
Try
Dim Command As New SqlClient.SqlCommand(strRequete, Connexion)
'Déclaration d'un tableau mémoire destiné à recevoir le résultat de la requête (SqlDataReader)
Dim SdrList As SqlClient.SqlDataReader
'Initialisation de celui ci
SdrList = Command.ExecuteReader
'On le parcour, tant qu'il existe encore une ligne à lire
Do While SdrList.Read()
'Ajout d'une ligne dans le treeview
TvListeSoc.Nodes.Add(SdrList("NomSociete"))
'Incrémentation de l'index
y = y + 1
i = SdrList("idSociete")
Do While i = SdrList("idSociete")
'Ajout d'une ligne dans le treeview, ligne qui aura pour parent le ligne d'index y
TvListeSoc.Nodes(y).Nodes.Add(SdrList("NomEmploye"))
SdrList.Read()
Loop
Loop
'Fermeture de SqlDataReader
SdrList.Close()
Connexion.Close()
Catch Probleme As Exception
MessageBox.Show("L'erreur suivante a été rencontrée : " + Probleme.Message, "Erreur")
End Try
Connexion.Close()
End If |