Praise be to Allah.
You may pray the duaa of Zakariya (peace be upon him), who said:
Rabbi laa tadharni fardan wa anta khayr ul-waaritheen (O my Lord! Leave me not single (childless), though You are the Best of the inheritors). This is a beautiful duaa which is very appropriate in this case. Also suitable is another prayer of Zakariya: Rabbi hab li min ladunka dhurriyyatan tayyibatan innaka samee al-duaa (O my Lord! Grant me from You a good offspring. You are indeed the All-Hearer of invocation).
The story of Zakariya contains valuable lessons for us. Allaah has told us this story in several places in the Quraan. For example, in Soorat Aal Imraan, where He tells us about Maryam (peace be upon her) He says (interpretation of the meaning):
So her Lord (Allaah) accepted her [Maryam] with goodly acceptance. He made her grow in a good manner and put her under the care of Zakariya. Every time he entered al-mihrab [a praying place or private room] to (visit) her, he found her supplied with sustenance. He said, O Maryam! From where have you got this? She said, This is from Allaah. Verily, Allaah provides sustenance to whom He wills, without limit.
At that time Zakariya invoked his Lord, saying: O my Lord! Grant me from You a good offspring. You are indeed the All-Hearer of invocation.
Then the angels called him, while he was standing in prayer in al-mihrab, (saying): Allaah gives you glad tidings of Yahya, confirming (believing in) the Word from Allaah [i.e., the creation of Eesaa], noble, keeping away from sexual relations with women, a Prophet, from among the righteous.
He said, O my Lord! How can I have a son when I am very old and my wife is barren? Allaah said: Thus Allaah does what He wills.
He said: O my Lord! Make a sign for me. Allaah said: Your sign is that you shall not speak to mankind for three days except with signals. And remember your Lord much, and glorify (Him) in the afternoon and in the morning.[Aal Imraan 3:37-41]
In Soorat Maryam, Allaah says (interpretation of the meaning):
(This is) a mention of the mercy of your Lord to His slave Zakariya.
When he called out to his Lord (Allaah) a call in secret,
Saying, My Lord! Indeed my bones have grown feeble, and grey hair has spread on my head, and I have never been unblest in my invocation to You, O my Lord!
And verily! I fear my relatives after me, since my wife is barren. So give me from Yourself an heir, -
Who shall inherit me, and inherit (also) the posterity of Yaqoob [inheritance of religious knowledge and Prophethood]. And make him, my Lord, one with whom You are well-pleased!
(Allaah said): O Zakariya! Verily, We give you the glad tidings of a son. His name will be Yahya. We have given that name to none before (him).
He said, My Lord! How can I have a son, when my wife is barren, and I have reached the extreme old age?
He said, So (it will be). Your Lord says: It is easy for Me, Certainly, I have created you before, when you had been nothing!
[Zakariya] said: My Lord! Appoint for me a sign. He said, Your sign is that you shall not speak unto mankind for three nights, though having no bodily defect.
Then he came out to his people from al-mihrab [a praying-place or private room] and told them by signs to glorify Allaahs Praises in the morning and in the afternoon.[Maryam 19:2-11]
In Soorat al-Anbiya, Allaah says (interpretation of the meaning):
And (remember) Zakariya, when he cried to his Lord: O my Lord! Leave me not single (childless), though You are the Best of the inheritors.
So We answered his call, and We bestowed upon him Yahya, and cured his wife (to bear a child) for him. Verily, they used to hasten on to do good deeds, and they used to call on Us with hope and fear, and used to humble themselves before Us.
Thinking about the story of Zakariya (peace be upon him) is very beneficial for anyone who is infertile. One may also ponder the story of Ibraaheem and his wife Saarah, whom Allaah rewarded for their patience with Ishaaq when Ibraaheem was very old. He was also given another son, Ismaaeel. Allaah tells us that His khaleel (friend) said (interpretation of the meaning):
All praises and thanks be to Allaah, Who has given me in old age Ismaaeel and Ishaaq. Verily! My Lord is indeed the All-Hearer of invocations.[Ibraaheem 14:39]
In all situations, the Muslim should accept and be content with the decree of Allaah, even if he is to remain infertile for the rest of his life. It could be that his patience may be better for him than a child. Everything that Allaah decrees has wisdom and a reason behind it, and everything is subject to His Will and Command. Allaah says (interpretation of the meaning):
To Allaah belongs the kingdom of the heaven and the earth. He creates what He wills. He bestows female (offspring) upon whom He wills, and bestows male (offspring) upon whom He wills.
Or He bestows both males and females, and He renders barren whom He wills. Verily, He is the All-Knower and is Able to do all things.
May Allaah bless our Prophet Muhammad.