public static List <TbCategoriaBE> SelectAll()
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["NorthWind"].ToString();
            string sql = "SELECT CategoryID, CategoryName FROM Categories";

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    List <TbCategoriaBE> Productos = new List <TbCategoriaBE>();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TbCategoriaBE objTbProducto = new TbCategoriaBE();
                            objTbProducto.CodCategoria = reader.GetInt32(0);
                            objTbProducto.NomCategoria = reader.GetString(1);
                            Productos.Add(objTbProducto);
                        }
                    }
                    connection.Close();
                    return(Productos);
                }
            }
        }
Example #2
0
        public static List <TbCategoriaBE> SelectAll()
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["Northwind"].ToString();
            string sql = "Select codCategoria,Nombre,Descripcion from TbCategoria";

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    List <TbCategoriaBE> Categorias = new List <TbCategoriaBE>();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TbCategoriaBE objcateg = new TbCategoriaBE();
                            objcateg.codCategoria = Convert.ToString(reader.GetInt32(0));
                            objcateg.Nombre       = reader.GetString(1);
                            Categorias.Add(objcateg);
                        }
                    }
                    return(Categorias);
                }
            }
        }