/// <summary> /// methode qui permet de supprimé un adherent /// </summary> /// <param name="ID"></param> /// <returns></returns> public Adherent DeleteAD(int ID) { Adherent ladherent = null; using (MySqlConnection conection = new MySqlConnection(connectionString)) { conection.Open(); string query = "DELETE from adherent Where id = @ID"; //Create Command MySqlCommand cmd = new MySqlCommand(query, conection); cmd.Parameters.AddWithValue("@id", ID); cmd.ExecuteNonQuery(); ladherent = new Adherent(); conection.Close(); } return(ladherent); }
/// <summary> /// La méthode Read retourne une liste adherent en fonction de son Nom dans la table. /// </summary> /// <param name="Nom">id du adherent recherché</param> /// <returns></returns> public List <Adherent> Read() { Adherent ladherent = null; List <Adherent> ListAD = new List <Adherent>(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); string query = "SELECT * FROM adherent"; //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command using (MySqlDataReader dataReader = cmd.ExecuteReader()) { //Read the data and store them in the list while (dataReader.Read()) { ladherent = new Adherent(); ladherent.SetID((int)dataReader["id"]); ladherent.SetNom((string)dataReader["Nom"]); ladherent.SetVille((string)dataReader["Ville"]); ladherent.SetAdresse((string)dataReader["Adresse"]); ladherent.SetDateNaissance((DateTime)dataReader["DateNaissance"]); ladherent.SetPrenom((string)dataReader["Prenom"]); ladherent.SetSexe((string)dataReader["Sexe"]); ladherent.SetCP((int)dataReader["CP"]); ladherent.SetNumLicence((int)dataReader["NumLicence"]); ladherent.SetCotisation((int)dataReader["Cotisation"]); ListAD.Add(ladherent); } } } return(ListAD); }