Ejemplo n.º 1
0
        public void UpdateAeroport(ViewModel.AeroportBinder a)
        {
            ConnectionBdd   bdd        = new ConnectionBdd();
            MySqlConnection connection = bdd.getConnection();

            MySqlCommand cmd = connection.CreateCommand();

            cmd.CommandText = "UPDATE aeroport SET `libelle`=@libelle,`aita`=@aita,`ville`=@ville,`pays`=@pays WHERE id=@id";

            cmd.Parameters.AddWithValue("@libelle", a.LibelleProperty);
            cmd.Parameters.AddWithValue("@aita", a.AitaProperty);
            cmd.Parameters.AddWithValue("@ville", a.VilleProperty);
            cmd.Parameters.AddWithValue("@pays", a.PaysProperty);
            cmd.Parameters.AddWithValue("@id", a.IdProperty);

            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 2
0
        // Méthode pour initialiser la connexion


        public void SelectAeroport(ObservableCollection <ViewModel.AeroportBinder> listeaeroports)
        {
            try
            {
                ConnectionBdd   bdd        = new ConnectionBdd();
                MySqlConnection connection = bdd.getConnection();
                // Requête SQL
                string query = "SELECT * from aeroport";

                MySqlCommand    cmd    = new MySqlCommand(query, connection);
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int    Id = reader.GetInt32(0);
                    string LibelleProperty = reader.GetString(1);
                    string AitaProperty    = reader.GetString(2);
                    string VilleProperty   = reader.GetString(3);
                    string PaysProperty    = reader.GetString(4);

                    ViewModel.AeroportBinder unaeroport = new ViewModel.AeroportBinder(Id, LibelleProperty, AitaProperty, VilleProperty, PaysProperty);

                    listeaeroports.Add(unaeroport);
                }

                //Fermeture de la connexion
                reader.Close();
                this.connection.Close();
            }
            catch
            {
                // Gestion des erreurs :
                // Possibilité de créer un Logger pour les exceptions SQL reçus
                // Possibilité de créer une méthode avec un booléan en retour pour savoir si le contact à été ajouté correctement.
            }
        }