コード例 #1
0
        public static List <DeporteItemVM> ObtenerReporte()
        {
            List <DeporteItemVM> resultado = new List <DeporteItemVM>();
            string cadenaConexion          = System.Configuration.ConfigurationManager.AppSettings["CadenaBD"].ToString();

            SqlConnection cn = new SqlConnection(cadenaConexion);

            try
            {
                SqlCommand cmd = new SqlCommand();

                string consulta = @"SELECT s.IdDeporte ,d.Nombre, count(*) Cantidad  FROM socios s INNER JOIN deportes d ON s.IdDeporte=d.Id
                                    group by s.IdDeporte, d.Nombre";
                cmd.Parameters.Clear();


                //ejecutara una consulta sql y le diremos cual va a ser el texto de la consulta
                cmd.CommandType = System.Data.CommandType.Text; // si fuera un procedimiento almacenado seria .storeProcedure
                // ahora le asigno el texto
                cmd.CommandText = consulta;

                cn.Open();
                cmd.Connection = cn;

                SqlDataReader dr = cmd.ExecuteReader();
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        DeporteItemVM aux = new DeporteItemVM();

                        aux.IdDeporte     = int.Parse(dr["IdDeporte"].ToString());
                        aux.NombreDeporte = dr["Nombre"].ToString();

                        aux.Cantidad = int.Parse(dr["Cantidad"].ToString());

                        ;
                        resultado.Add(aux);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
            return(resultado);
        }
コード例 #2
0
        public static List <DeporteItemVM> obtenerListaDeportes()
        {
            List <DeporteItemVM> resultado = new List <DeporteItemVM>();
            string cadenaConexion          = System.Configuration.ConfigurationManager.AppSettings["cadenaBD"].ToString();

            SqlConnection cn = new SqlConnection(@"Data Source=JGA_NOTEBOOK;Initial Catalog=master;Integrated Security=True");

            try
            {
                SqlCommand cmd = new SqlCommand();

                string consulta = "SELECT * FROM Deportes";

                cmd.Parameters.Clear();

                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = consulta;

                cn.Open();
                cmd.Connection = cn;
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr != null)
                {
                    while (dr.Read())
                    {
                        DeporteItemVM aux = new DeporteItemVM();
                        aux.Id     = int.Parse(dr["Id"].ToString());
                        aux.Nombre = dr["Nombre"].ToString();

                        resultado.Add(aux);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cn.Close();
            }

            return(resultado);
        }
コード例 #3
0
        public static List <DeporteItemVM> obtenerListaDeportes()
        {
            List <DeporteItemVM> resultado = new List <DeporteItemVM>();
            SqlConnection        cn        = new SqlConnection(cadenaConexion);

            try
            {
                SqlCommand cmd = new SqlCommand();

                string consulta = "SELECT * FROM Deportes";

                cmd.Parameters.Clear();

                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = consulta;

                cn.Open();
                cmd.Connection = cn;
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr != null)
                {
                    while (dr.Read())
                    {
                        DeporteItemVM aux = new DeporteItemVM();
                        aux.Id     = int.Parse(dr["Id"].ToString());
                        aux.Nombre = dr["Nombre"].ToString();

                        resultado.Add(aux);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cn.Close();
            }

            return(resultado);
        }
コード例 #4
0
        public static List <DeporteItemVM> ObtenerCantPorDeporte()
        {
            List <DeporteItemVM> listaDeportes = new List <DeporteItemVM>();
            string        stringConexion       = System.Configuration.ConfigurationManager.AppSettings["CadenaBD"].ToString();
            SqlConnection conn = new SqlConnection(stringConexion);

            try
            {
                SqlCommand cmd      = new SqlCommand();
                string     consulta = @"SELECT d.Nombre Nombre, COUNT(*) Cantidad
                                   FROM Deportes d JOIN Socios s ON s.IdDeporte = d.Id
                                  GROUP BY d.Nombre";
                cmd.Parameters.Clear();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = consulta;

                conn.Open();
                cmd.Connection = conn;
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr != null)
                {
                    while (dr.Read())
                    {
                        DeporteItemVM deporte = new DeporteItemVM();
                        deporte.pNombre   = dr["Nombre"].ToString();
                        deporte.pCantidad = int.Parse(dr["Cantidad"].ToString());

                        listaDeportes.Add(deporte);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(listaDeportes);
        }