Bonjour,

J'aimerai avoir votre avis concernant ma méthode, qui ne semble pas fonctionner...

Voici la méthode (dans la classe GestionClients) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public static List<Client> AfficheClient()
        {
            var ListClient = new List<Client>();
            bdd.connection.Open();
            var cmd = new MySqlCommand("SELECT CLI_CODE, CLI_NOM, CLI_PRENOM, CLI_ADRESSE_1, CLI_ADRESSE_2, CLI_CP, CLI_VILLE, CLI_MAIL FROM CLIENT;", bdd.connection);
            using (var reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    try
                    {
                        ListClient.Add(new Client
                        {
                            CLI_CODE = reader.GetString(0),
                            CLI_NOM = reader.GetString(1),
                            CLI_PRENOM = reader.GetString(2),
                            CLI_ADRESSE_1 = reader.GetString(3),
                            CLI_ADRESSE_2 = reader.GetString(4),
                            CLI_CP = reader.GetString(5),
                            CLI_VILLE = reader.GetString(6),
                            CLI_MAIL = reader.GetString(7)
                        });
 
                    }
                    catch (MySqlException e)
                    {
                        if (e.Source != null)
                            Console.WriteLine("IOException source: {0}", e.Source);
                    }
                }
 
            }
            bdd.connection.Close();
            return ListClient;
        }
Et voici là où je l'appel, dans la vue FenClients :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
public partial class FenClients : Form
    {
        private static Bdd bdd = new Bdd();
        private static Client c;
        List<Client> Clients = new List<Client>(); 
 
        public FenClients()
        {
            InitializeComponent();
            Clients = GestionClients.AfficheClient();
            try
            {
                CodeClientBoxText.Text = Clients.First().CLI_CODE;
                NomClientBoxText.Text = Clients.First().CLI_NOM;
                PrenomClientBoxText.Text = Clients.First().CLI_PRENOM;
                Adresse1ClientBoxText.Text = Clients.First().CLI_ADRESSE_1;
                Adresse2ClientBoxText.Text = Clients.First().CLI_ADRESSE_2;
                CPClientBoxText.Text = Clients.First().CLI_CP;
                VilleClientBoxText.Text = Clients.First().CLI_VILLE;
                MailClientBoxText.Text = Clients.First().CLI_MAIL;
            }
            catch 
            {
 
            }
 
        }
Ps : A savoir que je n'ai rien mit dans private void FenClients_Load(object sender, EventArgs e)

Et voici la classe bdd qui peut être utile :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Bdd
    {
 
        public MySqlConnection connection;
 
        // Constructeur
        public Bdd()
        {
            this.InitConnexion();
        }
 
        // Méthode pour initialiser la connexion
        public void InitConnexion()
        {
            // Création de la chaîne de connexion
            string connectionString = "SERVER=127.0.0.1; DATABASE=gestion_commercial; UID=root; PASSWORD=";
            this.connection = new MySqlConnection(connectionString);
        }
 
 
    }
Visual Studio 2015 ne m'affiche aucune erreur. Mais quand je lance l'application, les TextBox n'affiche rien. Je suppose donc que ListeClient est vide ^^

Merci pour toute aide.

Cordialement