I had the same problem. The gnats get into wet soil and breed there. For existing gnats, you can use a spray. I used a spray by Safer. However, this will not kill the breeding gnats in the soil. For that problem, there are many different brands of "Systemic Insect Granules". You simply water the soil and mix the granules into the top 1" layer of soil. You may need to reapply. Also, I found that the gnats seemed to breed more easily in plastic pots. AFter I transfered my
plants to regular clay, the problem remedied itself more quickly. Both products are available at Home Depot or Lowes or any hardware store..