示例#1
0
        public static List <Alumno> TraerTodos(string ciudad)
        {
            string     procedure = "TraerTodosPorCiudad";
            SqlCommand command   = new SqlCommand(procedure, AdminDB.ConectarDB());

            //definir tipo de comando
            command.CommandType = CommandType.StoredProcedure;
            //definir parametro
            command.Parameters.Add("@ciudad", SqlDbType.VarChar, 50).Value = ciudad;
            SqlDataReader reader = command.ExecuteReader();
            List <Alumno> lista  = new List <Alumno>();

            while (reader.Read())
            {
                lista.Add(new Alumno(
                              reader["Nombre"].ToString(),
                              reader["Apellido"].ToString(),
                              int.Parse(reader["DNI"].ToString()),
                              reader["Email"].ToString(),
                              reader["Ciudad"].ToString(),
                              int.Parse(reader["NroLegajo"].ToString())
                              ));
            }
            AdminDB.CerrarConexion();
            return(lista);
        }
示例#2
0
        public static List <Alumno> TraerTodos()
        {
            //1 connection
            //2 sql o spu
            string query = "SELECT [Id],[Nombre],[Apellido],[DNI],[Email],[Ciudad],[NroLegajo]FROM[dbo].[Alumno]";
            //3 comando SqlCommand
            SqlCommand command = new SqlCommand(query, AdminDB.ConectarDB());
            //4 objeto reader
            //5 invcocar SqlCommand y trabajar con el reader
            SqlDataReader reader = command.ExecuteReader();
            //6 crear la lista
            List <Alumno> lista = new List <Alumno>();

            while (reader.Read())
            {
                lista.Add(new Alumno(
                              reader["Nombre"].ToString(),
                              reader["Apellido"].ToString(),
                              int.Parse(reader["DNI"].ToString()),
                              reader["Email"].ToString(),
                              reader["Ciudad"].ToString(),
                              int.Parse(reader["NroLegajo"].ToString())
                              ));
            }
            AdminDB.CerrarConexion();
            return(lista);
        }