m0useanswered grow question a year ago BTi like poly has said or use a product called beneficial Nematodes. They are parasitic microscopic worms that eat the Larva and Eggs from the inside out.
I have had a really bad gnat infestation once. all my tent and all my house plants, I used that and they where all dead within a weeks time.
The brand I used is called nema globe pot poppers, I break open the little tea bag sachets they have and sprinkle the product in all my pots. can lightly bury them as well if you want or add into water.
Sticky traps kill adults but not normally before they breed and make more gnats.
I have also tried DE, it does not work as it gets wet, it also takes it time to kill them. Its like getting a bunch of small cuts of glass and they need time to bleed out.
I have also seen others advertise placing a 1 inch layer of sand on top of the pot as its hard for them to burrow into to lay eggs, but I don't have that kinda space in my pots and sad is heavy, don't need any compacting going on. You can get BTi in liquid form. advertised as caterpillar killer in most places. The adults die on their own quickly I never manage their life stage, I just focus on the eggs and larva.
Good Luck!