At the risk of sounding stereotypical, I grew up in a Kansas town and I spent my summers out in corn fields. We didn't own corn fields, although I had a friend that was a farmer, but my dad owned a crop consulting business, so we told the farmers when they needed to spray, how to optimize water usage and stuff like that. So I have some knowledge about buying sweet corn that I need to pass on to the rest of the kind folk on the internet.
About the corn at stores and markets: the problem with corn at the store is that it is generally picked too ripe after alot of the sugar in the kernels have switched to starch. This makes the corn taste not as good. Stores generally get the same corn as markets (or farm stands) do, but the people at markets probably only sale corn that will actually be good while stores just sell all the corn they get.
If you want to make sure that the corn that you are buying is good no matter where you get it pop one of the kernels that is in the middle of the ear with your fingernail and let the liquid dry on your nail. If it dries to be white the corn has alot of starch in it and won't taste good. If it dries and it is clear and slightly sticky then the corn has alot of sugar in it and will taste good.
Another thing to look for is if any of the kernels have indentions in them. This means that the ear of corn was picked after the corn plant started to dry itself out, that corn will not taste good.
Finally, this one is my pet peeve with sweet corn; make sure that the corn is actually a sweet corn variety and not a young field corn variety. Young field corn (the corn that farmers grow to make cow feed, which is what most corn grown does) looks and tastes like sweet corn. The problem is that field corn always will have more starch and has a flavor that just tastes a bit off. Now here is where the local farmer is at a disadvantage, alot of the time a farmer will plant field corn and sweet corn in the same field, and if the corn field is center pivot irrigated the sweet corn will be planted down the access road in the middle of the field. This means that the perfectly good sweet corn plants will most likely be pollinated by field corn and will make a hybrid that does not taste as good as it could be. So unless your local market is getting corn form a sweet corn only field the corn might not taste great. Grocery stores on the other hand probably only get corn from sweet corn only fields, so the corn might be better off genetically, but have the problems listed above. I'm not sure if everybody can taste the sweet corn hybrid that is sold, but since I know what young field corn tastes like I generally can tell if the corn is sweet corn or not. I guess this can be my talent.