private void Update() { DataBaseAccess.Connexion.Open(); MySqlCommand commandSql = DataBaseAccess.Connexion.CreateCommand(); commandSql.CommandText = _updateSql; commandSql.Parameters.Add(DataBaseAccess.CodeParam("?id", Id)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?prenom", Prenom)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?nom", Nom)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?email", Email)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?telephone", Telephone)); commandSql.Prepare(); commandSql.ExecuteNonQuery(); DataBaseAccess.Connexion.Close(); }
private void Insert() { DataBaseAccess.Connexion.Open(); MySqlCommand commandSql = DataBaseAccess.Connexion.CreateCommand(); commandSql.CommandText = _insertSql; commandSql.Parameters.Add(DataBaseAccess.CodeParam("?prenom", Prenom)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?nom", Nom)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?telephone", Telephone)); commandSql.Parameters.Add(DataBaseAccess.CodeParam("?email", Email)); commandSql.Prepare(); commandSql.ExecuteNonQuery(); MySqlCommand commandGetLastId = DataBaseAccess.Connexion.CreateCommand(); commandGetLastId.CommandText = _getLastInsertId; commandGetLastId.Parameters.Add(DataBaseAccess.CodeParam("?prenom", Prenom)); commandGetLastId.Parameters.Add(DataBaseAccess.CodeParam("?nom", Nom)); commandGetLastId.Parameters.Add(DataBaseAccess.CodeParam("?telephone", Telephone)); commandGetLastId.Parameters.Add(DataBaseAccess.CodeParam("?email", Email)); commandGetLastId.Prepare(); MySqlDataReader jeuEnregistrements = commandGetLastId.ExecuteReader(); bool existEnregistrement = jeuEnregistrements.Read(); if (existEnregistrement) { id = Convert.ToInt16(jeuEnregistrements["id"].ToString()); } else { commandSql.Transaction.Rollback(); throw new Exception("Duplicate entry"); } DataBaseAccess.Connexion.Close(); }