public List <RangoPrecio> FindAll() { string cadenaFindAll = "SELECT id ,fecha_ini, fecha_fin, variacion_precio FROM RangoPrecio"; List <RangoPrecio> listaRangos = new List <RangoPrecio>(); using (SqlConnection cn = BdSQL.Conectar()) { using (SqlCommand cmd = new SqlCommand(cadenaFindAll, cn)) { cn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null) { while (reader.Read()) { RangoPrecio unRP = new RangoPrecio(); unRP.Load(reader); if (unRP.Validar()) { listaRangos.Add(unRP); } } } } } return(listaRangos); }
public RangoPrecio FindById(int id) { string cadenaFind = "SELECT fecha_ini, fecha_fin, variacion_precio FROM RangoPrecio WHERE id = @id"; RangoPrecio unRP = null; using (SqlConnection cn = BdSQL.Conectar()) { using (SqlCommand cmd = new SqlCommand(cadenaFind, cn)) { cmd.Parameters.AddWithValue("@id", id); cn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader != null && reader.Read()) { unRP = new RangoPrecio(); unRP.Load(reader); unRP.Id = id; } } } return(unRP); }