Gnats can be killed by spraying them with a baking soda and vinegar solution, by swatting them, by using electronic insect killers and by the use of pesticides. Even more important than killing the gnats is eliminating whatever is attracting the gnats into the house in the first place.
Gnats die when they are sprayed with a solution composed of dish soap, baking soda, vinegar and water. Because this solution contains no pesticides, it does not harm plants or contaminate cooking surfaces. As Orkin points out, pesticides also kill gnats, but they are best applied by a pest control professional.
Flying insects, such as gnats, are attracted to the ultraviolet light used in electronic insect killers. These devices should only be used outside, however, so they are of little use when gnats invade a home. Gnats can also be killed with a simple flyswatter, but this technique may be insufficient when dealing with a large infestation.
One of the keys to ridding a house of gnats is to eliminate the elements that attracted the gnats originally. Gnats are drawn to pools of standing water, including the small amounts of water left when indoor plants are watered. The soil of indoor plants should be allowed to dry completely before watering in order to minimize gnats. In addition, gnats are attracted to ripe fruits. Fruit should be stored in the refrigerator to avoid attracting gnats.