public static void enregistrerTech(tech unTech) { 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 technicien VALUES (@MatriculeT, @Nom, @Prenom, @NivInterv, @Formation, @Competence)"; cmd.Parameters.AddWithValue("@MatriculeT", unTech.matriculeT); cmd.Parameters.AddWithValue("@Nom", unTech.nom); cmd.Parameters.AddWithValue("@Prenom", unTech.prenom); cmd.Parameters.AddWithValue("@NivInterv", unTech.nivInterv); cmd.Parameters.AddWithValue("@Formation", unTech.formation); cmd.Parameters.AddWithValue("@Competence", unTech.competence); cmd.ExecuteNonQuery(); MessageBox.Show("Ajouter à la base !"); conn.Close(); }
public static List <tech> selectTech() { List <tech> LesTechs = new List <tech>(); 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 MatriculeT, Nom, Prenom, NivInterv, Formation, Competence FROM technicien"; MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { tech unTech = new tech(Convert.ToString(dataReader["MatriculeT"]), Convert.ToString(dataReader["Nom"]), Convert.ToString(dataReader["Prenom"]), Convert.ToString(dataReader["NivInterv"]), Convert.ToString(dataReader["Formation"]), Convert.ToString(dataReader["Competence"])); LesTechs.Add(unTech); } conn.Close(); return(LesTechs); }
private void buttonAjtT_Click(object sender, EventArgs e) { tech letech = new tech(textBoxMatriculeT.Text, textBoxNomT.Text, textBoxPrenomT.Text, textBoxNivUrgT.Text, textBoxFormationT.Text, textBoxComptT.Text); BD.enregistrerTech(letech); }