Aside from being annoying, your dog's trash-digging fetish can be dangerous and potentially fatal -- he might get poisoned or his digestive system might get perforated or obstructed. Scolding and punishing your pet companion after the fact is ineffective, because he's long forgotten about his treasure hunt and won't know what you're fussing about. Instead, try to catch him in the act when you're at home, and when you're away, booby-trap the trash can to give your dog an unforgettable experience that will keep him from raiding the trash.
Observe your dog closely each time he's near the trash. Don't leave him out of your sight, because to correct his behavior, you must catch him as soon as he starts showing interest in the trash.
Shake a can of coins or clap your hands and firmly say "off," when your pet companion goes for the trash can. This will startle your dog and stop him in his tracks. If he continues to go for the trash can, repeat the "off" command and take him out of the room by his collar. Be consistent and do this each time you catch your dog in the act.
Redirect your dog's attention to acceptable activities. Hide small dog treats throughout the house and encourage him to go on a scavenger hunt for them. Alternatively, give him a food-stuffed dog toy to keep him busy.
Booby-trap the trash can when you're unable to watch your dog. Tie a dog treat to a string and attach it to an empty soda can. Build a pyramid of empty soda cans near the edge of a table above the trash can. Position the can with the string at the bottom of the pyramid. Place the string with the treat over the trash can. When your dog goes for the treat, the cans fall and startle him away from the trash. Alternatively, use commercial deterring gadgets that emit a scary noise to scare your dog away from the trash.
Spray the trash can with a commercial dog repellent. Your dog dislikes the taste of the repellent and will most likely leave the trash can alone. Alternatively, sprinkle baking soda on the can for a similar effect.