Hello and welcome to eHealth Forum!
As you have rightly understood your problem of maintain an erection is due to uncontrolled diabetes. Persistent high levels of blood sugar results in poor blood supply and damage to nerve endings, both of which are necessary to maintain a good erection. The autonomic nervous system (sympathetic and parasympathetic) is also affected resulting in further problems in maintain erection.
The symptoms can be brought under control by effectively treating diabetes and then treating the problem. You should consult a specialist in this field and keep your blood sugar under control by diet, exercise and medicines.
There is not much that can be advised on net except that it is necessary to control blood sugar first. This cannot be achieved without medical help. Hope this helps. Take care!