A rice-looking grain around the dog's anus and in your pet's excrement is likely a piece of tapeworm. When freshly excreted they move and appear flat. Tapeworms are introduced into the animal when they eat a flea carrying the egg(s) of the worm. The worm attaches to the intestine and grows long, in segments that break off and exit in the animals feces. http://www.marvistavet.com/html/body_tapeworm.html
Medications for tapeworms are best from your vet since the commercial products may not address the particular worm, could aggravate other conditions and/or cause any of a number of other bad reactions.
If your animal is on heartworm medication, vet monitored meds for any/all other parasite (worm) infestations is necessary. If your animal has any history of thyroid or liver disease (or anything else) - medically supervised treatment is necessary.
Roundworms and Hookworms are most typical in puppies and they're often the cause of big, round belly. These worms are picked up from the ground and while adult animals don't usually have them, pregnant mothers can pass the eggs on to her unborn pups (explaining why so many puppies are born with worms). Worming the mother has no effect - the puppies must be treated. http://www.petshealth.com/dr_library/wormsdog.html
Whipworms live higher up in the intestine and many times aren't visible in excrement. If/when they are, they are often seen as short pieces of string with a flat end. Not only is vet diagnosis necessary for these, but again, professional treatment recommended.
Again, while you can buy over the counter treatments, it's better to do it right and do it once - make a vet visit. It is much less expensive than trying to correct a problem caused by the commercial med and possible complications.