예제 #1
0
        public static List <Avion> AllAvion()
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;
            connection.Open();
            command.CommandText = @"SELECT Identifiant, Nom, IdentifiantModele
                FROM Avion;";


            MySqlDataReader reader = command.ExecuteReader();
            List <Avion>    avions = new List <Avion>();
            Avion           a      = null;

            while (reader.Read())
            {
                a                   = new Avion();
                a.Identifiant       = reader.GetInt32("Identifiant");
                a.IdentifiantModele = reader.GetInt32("IdentifiantModele");
                a.Nom               = reader.GetString("Nom");

                avions.Add(a);
            }


            connection.Close();
            return(avions);
        }
예제 #2
0
        public static Avion GetAvion(int id)
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;
            connection.Open();
            command.CommandText = @"SELECT Identifiant, Nom
                FROM Avion 
                WHERE Identifiant =" + id + ";";

            command.Parameters.AddWithValue("Identifiant", id);
            MySqlDataReader reader = command.ExecuteReader();
            Avion           a      = null;

            if (reader.Read())
            {
                a             = new Avion();
                a.Identifiant = reader.GetInt32("Identifiant");
                a.Nom         = reader.GetString("Nom");
            }

            connection.Close();
            return(a);
        }