Exemplo n.º 1
0
        public static List <Modele> AllModele()
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;
            connection.Open();
            command.CommandText = @"SELECT Identifiant, version, nombreMoteurs, identifiantConstructeur
                FROM Modele;";


            MySqlDataReader reader  = command.ExecuteReader();
            List <Modele>   modeles = new List <Modele>();
            Modele          m       = null;

            while (reader.Read())
            {
                m                         = new Modele();
                m.Identifiant             = reader.GetInt32("Identifiant");
                m.IdentifiantConstructeur = reader.GetInt32("IdentifiantConstructeur");
                m.NombreDeMoteur          = reader.GetInt32("nombreMoteurs");
                m.Version                 = reader.GetString("Version");

                modeles.Add(m);
            }

            connection.Close();
            return(modeles);
        }
Exemplo n.º 2
0
        public static Modele GetModele(int id)
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;
            connection.Open();
            command.CommandText = @"SELECT Identifiant, version, nombreMoteurs, identifiantConstructeur
                FROM Modele
                Where identifiant =" + id + ";";

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

            if (reader.Read())
            {
                m                         = new Modele();
                m.Identifiant             = reader.GetInt32("Identifiant");
                m.IdentifiantConstructeur = reader.GetInt32("IdentifiantConstructeur");
                m.NombreDeMoteur          = reader.GetInt32("nombreMoteurs");
                m.Version                 = reader.GetString("Version");
            }

            connection.Close();
            return(m);
        }
Exemplo n.º 3
0
        public static int InsertModele(Modele modele)
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            connection.Open();

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;


            command.CommandText = $@"
                                INSERT INTO Modele(version, nombreMoteurs) 
                                VALUES(@version, @nombremoteurs);";

            command.Parameters.AddWithValue("@version", modele.Version);
            command.Parameters.AddWithValue("@nombremoteurs", modele.NombreDeMoteur);
            int ajout = command.ExecuteNonQuery();

            connection.Close();
            return(ajout);
        }
Exemplo n.º 4
0
        public static int UpdateModele(Modele modele)
        {
            MySqlConnection connection = new MySqlConnection(ConnectionString);

            connection.Open();

            MySqlCommand command = new MySqlCommand();

            command.Connection = connection;


            command.CommandText = @"UPDATE Modele SET Identifiant = @Identifiant, Version = @Version, nombreMoteurs = @nbMoteur
                                    WHERE Modele.Identifiant = @Identifiant;";



            command.Parameters.AddWithValue("@Identifiant", modele.Identifiant);
            command.Parameters.AddWithValue("@Version", modele.Version);
            command.Parameters.AddWithValue("@nbMoteur", modele.NombreDeMoteur);
            int update = command.ExecuteNonQuery();

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