Пример #1
0
        public static uf obtenerUF(int MES, int año)
        {
            uf retorno = new uf();

            DateTime finDeMes = new DateTime(año, MES, 1);
            int mes = finDeMes.Month;
            DateTime temp = finDeMes;
            while (temp.Month == mes)
            {
                finDeMes = temp;
                temp = temp.AddDays(1);
            }

            SqlConnection cnx = conexion.crearConexion();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnx;
            cmd.CommandText = "SELECT * FROM uf WHERE fecha=@fecha";
            cmd.CommandType = CommandType.Text;

            cmd.Parameters.Add("@fecha", SqlDbType.DateTime).Value= finDeMes;

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                retorno.fecha = (DateTime)dr["fecha"];
                retorno.valor = double.Parse(dr["valor"].ToString());
            }

            cnx.Close();

            return retorno;
        }
Пример #2
0
        public static uf obtenerUltimaUF()
        {
            uf retorno = new uf();

            SqlConnection cnx = conexion.crearConexion();

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cnx;
            cmd.CommandText = "SELECT TOP 1 * FROM uf ORDER BY fecha DESC";
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                retorno.fecha = (DateTime)dr["fecha"];
                retorno.valor = double.Parse(dr["valor"].ToString());
            }

            cnx.Close();

            return retorno;
        }