public List <StayLength> GetStayLengths() { List <StayLength> stayLengths = new List <StayLength>(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connect; cmd.CommandText = "SELECT sl.id, sl.name" + " FROM stay_length sl" + " ORDER BY sl.id"; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { StayLength stayLength = new StayLength() { Id = reader.GetInt32(0), Name = reader.GetValue(1).ToString(), }; stayLengths.Add(stayLength); } } } return(stayLengths); }
public StayLength GetStayLength(string name) { StayLength stayLength = null; MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connect; cmd.CommandText = "SELECT sl.id, sl.name" + " FROM stay_length sl" + $@" WHERE sl.name = '{name}'" + " ORDER BY sl.id"; using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { reader.Read(); stayLength = new StayLength() { Id = reader.GetInt32(0), Name = reader.GetValue(1).ToString(), }; } } return(stayLength); }