public List <Affectation> ReadAff() { Affectation uneAff = null; List <Affectation> listAff = new List <Affectation>(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); string query = "SELECT * FROM affectation"; //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()) { uneAff = new Affectation(); uneAff.SetId((int)dataReader["id"]); uneAff.SetId_adherent((int)dataReader["id_ad"]); uneAff.SetId_club((int)dataReader["id_cd"]); listAff.Add(uneAff); } } } return(listAff); }
/// <summary> /// methode qui lie la classe adherent et club a la table affectation /// </summary> /// <param name="idA"></param> /// <param name="idC"></param> /// <returns></returns> public Affectation Liaison(int idA, int idC) { Affectation aff = null; using (MySqlConnection conection = new MySqlConnection(connectionString)) { conection.Open(); string query = "Insert into affectation (id_adherent, id_club) values (@idA, @idC)"; //Create Command MySqlCommand cmd = new MySqlCommand(query, conection); cmd.Parameters.AddWithValue("@idA", idA); cmd.Parameters.AddWithValue("@idC", idC); cmd.ExecuteNonQuery(); aff = new Affectation(); conection.Close(); } return(aff); }