Miscarried

Anmber
So we have been trying to get pregnant for a few months now and the other night my boyfriend took me to the hospital because we thought my period was acting up and being weird only to find out i was pregnant and I'm miscarring. My heart is so broken it was my first pregnancy and I had no Idea I was pregnant. I feel so guilty what did I do wrong? Can anyone please give me advice. 
How long did u wait to try again