public void UpdatePlage(DOPlage obj) { if (obj != null) { string query = "UPDATE " + _table + "(nom, departement, Commune_idCommune) " + "VALUES('" + obj.nom + "', '" + obj.departement + "', '" + obj.commune + "')"; this.OpenConnection(); { MySqlCommand cmd = new MySqlCommand(query, this.connection); int rows = cmd.ExecuteNonQuery(); // check ... ? } this.CloseConnection(); } }
public void InsertPlage(DOPlage obj) { if (obj != null) { string query = "INSERT INTO " + _table + "(nom, departement, Commune_idCommune) " + "VALUES('" + obj.nom + "', '" + obj.departement + "', '" + obj.commune + "')"; this.OpenConnection(); { MySqlCommand cmd = new MySqlCommand(query, this.connection); int rows = cmd.ExecuteNonQuery(); // check rows pour vérifier qu'il y a bien eu insertion ? // get de l'id de la dernière row insérée } this.CloseConnection(); } }
public void SelectPlageById(int id, DOPlage obj) { DOPlage selected = new DOPlage(); string query = "SELECT * FROM " + _table + " WHERE idPlage = '" + id + "';"; this.OpenConnection(); { MySqlCommand cmd = new MySqlCommand(query, this.connection); int rows = cmd.ExecuteNonQuery(); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { obj.idPlage = reader.GetInt32(0); obj.nom = reader.GetString(1); obj.departement = reader.GetString(2); obj.commune = reader.GetInt32(3); } reader.Close(); } this.CloseConnection(); }
public List <DOPlage> SelectPlages() { List <DOPlage> col = new List <DOPlage>(); string query = "SELECT * FROM " + _table + ";"; this.OpenConnection(); { MySqlCommand cmd = new MySqlCommand(query, this.connection); int rows = cmd.ExecuteNonQuery(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DOPlage obj = new DOPlage(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetInt32(3)); col.Add(obj); } reader.Close(); } this.CloseConnection(); return(col); }