The best way to prevent and get rid of gnats is with biological controls. Bti/Mosquito Dunks is a bio-control, and it does work fairly well for helping get rid of gnats but is better applied before you have any in the first place.
If you have a bad infestation you need to take multiple steps to eradicate them. Predator mites are the single best solution I have found. You can spray anything you want, drench your soil with neem oil, etc. and it will only work if you keep applying the stuff. You'll probably never completely eradicate them this way, and once you stop your gnats are just going to bounce back.
Predator mites like the Hypoaspis sp. are micro-arthropods about a millimeter or two large. They eat fungus gnat eggs, pupae and small larvae, as well as over a hundred other species of soil-dwelling pests. They play an important role in the soil food web essentially turning the gnats into fertilizer, shredding organic matter, shuttling and dispersing microbes. You can use them along with Bti and beneficial nematodes, although the mites may eat some of the nematodes.