Sometimes, there's absolutely nothing you can do to stop from fainting, but if you feel it coming on there are a few things that may help.
Knowledge is half the battle. Victims of multiple fainting spells should definitely see a doctor and determine the cause of the fainting (if any). Victims will often learn the warning signs and symptoms of fainting and can learn to avoid it.
The best way to prevent fainting is too lie down when the symptoms start. Sometimes that will prevent fainting entirely, but if it doesn't, at least the victim won't fall.
Avoid dehydration; drink plenty of fluids.
If you feel suddenly flushed, hot, nauseated or break out in a cold sweat, don't stand up. Lie down until it passes. If it doesn't pass in a few minutes or you begin to experience chest pain or shortness of breath, call 911.