public List <FoulType> GetFoulsType(string text) { List <FoulType> result = new List <FoulType>(); using (MySqlConnection conn = new MySqlConnection(_connection)) { try { conn.Open(); } catch (Exception) { return(result); } string sql = text.Equals("") ? "select * FROM typefouls" : $"select * FROM typefouls WHERE typename LIKE '%{text}%'"; using (MySqlCommand command = new MySqlCommand(sql, conn)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { FoulType foulType = new FoulType(); foulType.Id = reader.GetInt32(0); foulType.Type = reader.GetString(1); result.Add(foulType); } } } } return(result); }
internal void UpdateFoulType(FoulType foulType) { using (MySqlConnection conn = new MySqlConnection(_connection)) { try { conn.Open(); } catch (Exception) { } using (MySqlCommand command = new MySqlCommand()) { command.Connection = conn; command.CommandText = $"UPDATE typefouls SET type='{foulType.Type}' WHERE id = {foulType.Id}"; try { command.ExecuteNonQuery(); } catch (Exception) { } } } }