Missed miscarriage

So I am diabetic with pcos, I’ve been trying to have a baby with my husband for 4 years .. I am over weight and went from 280 down to 198 in a year and a half. I found out we were expecting at 5 weeks. Everything was going well and had mild cramping at 6 weeks.. went to the ER and said everything was fine .. I was even Able to see the heart beat.. they sent me home .. I had my first appointment at “7 weeks and 3 days.. they couldn’t find the heart beat.. I went in the following day to confirm.. and still no heart beat.. I am devastated.. I asked when this happened as my angel was charting at 6 weeks 3 days. I went in this past Friday for a d&c; and am an emotional wreck. My husband is so supportive and there for me.. and wants to try again in a few months once I can get my diabetes under control.. the dr thinks that may be the cause of the miscarriage.. I feel like all this is my fault.. if I had been taking better care of my diabetes.. I may not be going through this now.. how could this happen? I just don’t understand..