In recent years, lactose-free and low-lactose infant formulas have been increasingly used. The impact of using different carbohydrates than lactose on later cognition of formula-fed infants remains, however, unknown. We examined the effects of providing formulas containing either digestible maltodextrin or lactose as main carbohydrate source (28% of total nutrient composition) on cognitive performance of piglets. Piglets received the formulas from 1 to 9 weeks of age and, starting at 12 weeks, were individually tested in a spatial holeboard task (n = 8 pens/formula), in which they had to learn and memorize a configuration of baited buckets. After 28 acquisition trials, piglets were subjected to 16 reversal trials in which the location of the baited buckets was changed. Piglets fed the maltodextrin-based formula had higher reference memory (RM) scores than piglets fed the lactose-based formula towards the end of acquisition. During the switch of configuration, piglets offered the maltodextrin-based formula tended to have higher RM scores and make fewer RM errors than piglets offered the lactose-based formula. Working (short-term) memory was not affected by the formulas. Compared to lactose, the use of maltodextrin in milk formulas improved long-term spatial memory of piglets, even weeks after the end of the intervention.