Because of your promise, and according to your own heart, you have brought about all this greatness, to make your servant know it.
We have here the solemn address David made to God, in answer to the gracious message God had sent him. We are not told what he said to Nathan; no doubt he received him very kindly and respectfully as God's messenger. But his answer to God he took himself, and did not send by Nathan.
Commenting on 2 Samuel 7:18-29
For thy word's sake,.... For the sake of the promise he had made to him by Samuel, that he should be king, and his kingdom should be established; or for the sake of the Messiah, that should spring from him; the Memra, as the Targum, the essential Word of God; and so the Septuagint version, "because of thy servant", with which agrees the parallel text...
2Sa 7:21-22 “For Thy word’s sake, and according to Thy heart (and therefore not because I am worthy of such grace),has Thou done all this greatness, to make it known to Thy servant.” The word, for the sake of which God had done such great things for David, must be some former promise on the part of God.
Commenting on 2 Samuel 7:21-22