Q2. Under what condition can a two-wire receptacle be replaced with a three-wire receptacle, when no ground is available in the box?
A. Where no equipment bonding means exists in the outlet box, nongrounding-type receptacles can be replaced with [406.3(D)(3)]:

  • Another nongrounding-type receptacle.
  • A GFCI grounding-type receptacle marked "No Equipment Ground."
  • A grounding-type receptacle, if GFCI protected and marked "GFCI Protected" and "No Equipment Ground."
Basically, if you only have two wires in the box you will need to replace the outlet with a GFI

Note: GFCI protection functions properly on a 2-wire circuit without an equipment grounding (bonding) conductor, because the equipment grounding (bonding) conductor serves no role in the operation of the GFCI-protection device.

CAUTION: The permission to replace nongrounding-type receptacles with GFCI-protected grounding-type receptacles doesn't apply to new receptacle outlets that extend from an existing ungrounded outlet box. Once you add a receptacle outlet (branch-circuit extension), the receptacle must be of the grounding (bonding) type and it must have its grounding terminal grounded (bonded) to an effective ground-fault current path in accordance with 250.130(C).

If you need a grounding wire for some other reason, say proper operation of electronics, sound system, some control board or other sensitive electronic equipment, you will have to run new compliant wire back to the grounded part of the premise wiring.  Before 1994 you could just grab the cold water pipe at any place in the system,

Under the 1990 NEC {250-50(b)Exception} and in earlier code cycles a bonding jumper was permitted to be run from the grounding terminal of the receptacle to any water pipe that was bonded in accordance with 250-80(a).
250-80(a) Metal Water Piping. The interior metal water piping system shall be bonded to the service equipment enclosure, the grounded conductor at the service, the grounding electrode conductor where of sufficient size, or to the one or more grounding electrodes used.
But no longer
You cannot just hook to a water line anywhere. I have seen that done and there was plastic pipe coming in. No good.
See also :