All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
Not being able to produce children is not an obstacle for the continuity of marriage. So it is permissible for the man to keep his wife even if he is barren. You should know that every disease has a cure, so you should not be despaired from seeking treatment. The Prophet said: "There is a cure for every disease, so when the cure coincides with the disease, the person is cured, Allaah willing." [Muslim] Therefore, you should invoke Allaah earnestly, as the dominion is in His Hands, and all the good is in His Hands. Allaah Says (what means): {To Allaah belongs the dominion of the heavens and the earth; He creates what He wills. He gives to whom He wills female [children] and He gives to whom He wills males. Or He makes them [both] males and females, and He renders whom He wills barren. Indeed, He is Knowing and Competent.}[Quran 42:49].
Allaah Knows best.