A tooth has two parts- crown and a root. Now going from outside to inside the crown portion has 3 layers- enamel, dentin and pulp. The root has 3 layers- cementum, dentin and pulp. ReferenceReference Now among these only pulp is vascular and innervated. Dentin has got dentinal tubules containing dentinal fluid. Whenever there is any stimulus which has not yet reached the pulp, but may have reached the dentin, eg of stimulus in the form of pressure, temperature change, sweet food, sour food etc, cause the fluid to move or get displaced. The displacement of dentinal fluid stimulates nerve endings in the pulp and hence generates a pain/ sensitivitysensitivity response to your brain. Reference
There are three main theories of dentine hypersensitivity: Direct Innervation (DI) Theory Odontoblast Receptor (OR) Theory Fluid Movement/Hydrodynamic Theory
The Hydrodynamic or Fluid Movement theory is one of the main theories in dentistry to explain the mechanism by which a tooth perceives the sensation of pain. It is currently the most widely accepted theory used to explain tooth sensitivity.
Now coming back to your question. As the tooth is cracked, the enamel in that area must have been chipped off and the dentinal tubules and/or pulp must have been exposed. As mentioned earlier the sweet food also causes the dentinal fluid to be displaced causing a sharp shooting pain as perceived by your brain. This is because of change is osmolarity. The sweets/sugars changes the osmolarity of dentinal fluid.
Clinically, osmotic stimuli such as a wide variety of sweet food, particularly chocolate and sugar syrup, are one of the main factors causing dentin hypersensitivity. Previous studies showed that the different stimuli, including osmotic, when applied to dentin caused pain by a hydrodynamic mechanism that involves displacement of the dentinal fluid and excites intradental nerve endings. ReferenceReference
Hope I have satisfactorily answered your question :)