Exemplo n.º 1
0
        public static void enregistrerMateriel(materiel unMateriel)
        {
            string          connString = "Server = 127.0.0.1; Database = gsb_medic;Uid=dev;password=admin;SslMode=none;";
            MySqlConnection conn       = new MySqlConnection(connString);

            conn.Open();

            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "INSERT INTO materiel VALUES (@idM, @processeur, @disque, @memoire, @dateAchat, @garantie, @prix)";
            cmd.Parameters.AddWithValue("@idM", unMateriel.IdM);
            cmd.Parameters.AddWithValue("@processeur", unMateriel.Processeur);
            cmd.Parameters.AddWithValue("@disque", unMateriel.Disque);
            cmd.Parameters.AddWithValue("@memoire", unMateriel.Memoire);
            cmd.Parameters.AddWithValue("@dateAchat", unMateriel.DateAchat);
            cmd.Parameters.AddWithValue("@garantie", unMateriel.Garantie);
            cmd.Parameters.AddWithValue("@prix", unMateriel.Prix);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Ajouter à la base !");
            conn.Close();
        }
Exemplo n.º 2
0
        public static List <materiel> selectMateriel()
        {
            List <materiel> LesMateriels = new List <materiel>();

            string          connString = "Server = 127.0.0.1; Database = gsb_medic;Uid=dev;password=admin;SslMode=none;";
            MySqlConnection conn       = new MySqlConnection(connString);

            conn.Open();

            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT idM, processeur, disque, memoire, dateAchat, garantie, prix FROM materiel";
            MySqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                materiel unMateriel = new materiel(Convert.ToString(dataReader["idM"]), Convert.ToString(dataReader["processeur"]), Convert.ToString(dataReader["disque"]), Convert.ToString(dataReader["memoire"]), Convert.ToDateTime(dataReader["dateAchat"]), Convert.ToString(dataReader["garantie"]), Convert.ToString(dataReader["prix"]));
                LesMateriels.Add(unMateriel);
            }

            conn.Close();
            return(LesMateriels);
        }