Nathan commended David for his desire to build a temple and then went to his own house. That night God spoke to the prophet, and as an obedient servant, Nathan brought the word to David. The message was no.
God was not going to allow David to build a house of worship for Him. The Lord, however, was pleased with the intentions and the attitude of David's heart in this matter.
Years later, after David's death, Solomon built a magnificent temple and in his dedication message said, "It was in the heart of David my father to build an house for the name of the LORD God of Israel. And the Lord said unto David my father, Whereas it was in thine heart to build an house unto my name, thou didst well that it was in thine heart" (I Kings 8:17,18).
Though God said no to David's building a temple, He was so pleased with David's attitude that He made a covenant with him in which He promised to establish the house of David forever.
Can you take a no from God? He knows what is best for all of us. Remember, His promise to David was "I will be with thee for ever" (see 2 Sam. 7:16). This promise is ours also, for He has said He will never leave us nor forsake us (see Heb. 13:5).
"As for God, his way is perfect" (2 Sam. 22:31).