public static List <SocioItemVM> ObtenerListaSocios()
        {
            List <SocioItemVM> resultado      = new List <SocioItemVM>();
            string             cadenaConexion = System.Configuration.ConfigurationManager.AppSettings["CadenaBD"].ToString();

            SqlConnection cn = new SqlConnection(cadenaConexion);

            try
            {
                SqlCommand cmd = new SqlCommand();

                string consulta = @"SELECT s.Nombre, s.Apellido, s.NroDocumento, d.Nombre Deporte FROM socios s INNER JOIN deportes d ON s.IdDeporte=d.Id";
                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())
                    {
                        SocioItemVM aux = new SocioItemVM();

                        aux.Nombre   = dr["Nombre"].ToString();
                        aux.Apellido = dr["Apellido"].ToString();

                        aux.NroDocumento  = dr["NroDocumento"].ToString();
                        aux.DeporteNombre = dr["Deporte"].ToString();
                        ;
                        resultado.Add(aux);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
            return(resultado);
        }
示例#2
0
        public static List <SocioItemVM> ObtenerReportePersona()
        {
            List <SocioItemVM> resultado      = new List <SocioItemVM>();
            string             cadenaConexion = System.Configuration.ConfigurationManager.AppSettings["CadenaBD"].ToString();

            SqlConnection cn = new SqlConnection(cadenaConexion);

            try
            {
                SqlCommand cmd      = new SqlCommand();
                string     consulta = @"SELECT s.Id, s.Nombre, s.Apellido, s.IdTipoDocumento, s.NroDocumento, d.Nombre AS 'Deporte'
                                    FROM Socios s
                                    INNER JOIN Deportes d ON s.IdDeporte= d.Id";

                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())
                    {
                        SocioItemVM aux = new SocioItemVM();
                        aux.id            = int.Parse(dr["Id"].ToString());
                        aux.nombre        = dr["Nombre"].ToString();
                        aux.apellido      = dr["Apellido"].ToString();
                        aux.nombreTipoDoc = dr["IdTipoDocumento"].ToString();
                        aux.nroDoc        = int.Parse(dr["NroDocumento"].ToString());
                        aux.nombreDeporte = dr["Nombre"].ToString();

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