示例#1
0
        public static void ajouterMateriel(materiel unMateriel)
        {
            //Connexion
            String          connString = "Server = 127.0.0.1; Database = gsb_medic; Uid = dev; Password = Az123@; SslMode = none;";
            MySqlConnection conn       = new MySqlConnection(connString);

            conn.Open();
            try
            {
                // Requete SQL
                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO materiel(idM, processeur, disque, memoire, garantie, ticket) VALUES(@idM, @processeur, @disque, @memoire, @garantie, @ticket)";
                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("@garantie", unMateriel.Garantie);
                cmd.Parameters.AddWithValue("@ticket", unMateriel.Ticket);
                cmd.ExecuteNonQuery();

                MessageBox.Show("Enregistré dans la base !", "Réussite", MessageBoxButtons.OK);
            }
            catch (SqlException exp)
            {
                MessageBox.Show(exp.Message);
            }
            finally
            {
                conn.Close();
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Instanciation pour intéragir avec la base de données
            materiel unMateriel = new materiel(idTextBox1.Text, processeurTextBox2.Text, disqueTextBox3.Text, memoireTextBox4.Text, garantieTextBox5.Text, int.Parse(ticketTextBox6.Text));

            BD.ajouterMateriel(unMateriel);
        }
示例#3
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 = Az123@; SslMode=none;";
            MySqlConnection conn       = new MySqlConnection(connString);

            conn.Open();

            MySqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT idM, processeur, disque, memoire, garantie, ticket 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.ToString(dataReader["garantie"]), Convert.ToInt16(dataReader["ticket"]));
                LesMateriels.Add(unMateriel);
            }

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