The Holy Spirit in Scripture presents an unvarnished picture of the people of Scripture. We see not only the positive things about their lives, but also their weaknesses, faults, and sin.
King David of the Old Testament is no exception. He comes on the scene of Israel as a young shepherd boy, who against all odds, and above all his brothers, is chosen by God to be the king of Israel. We see him used by God to fell the great giant Goliath, with nothing more than a sling and five smooth stones. We hear his heart for God in the Psalms. We are told that he is a man after God's own heart. We hear the women of Israel sing, "Saul has slain his thousands, but David his ten thousands." Yet we also see his adultery with Bathsheeba, and then his plotting to have her husband murdered to cover it up.
Our assesment of the character of David would be a mixture of assets, and yet very serious liablities. We would not conclude that he always obeyed the Lord.
Yet notice God's assesment of his life many years after his death. "and yet you have not been like my servant David, who kept my commandments and followed me with all his heart, doing only that which was right in my eyes," (1 Kings 14:8 ESV)
Wait a minute God, what about Bathsheba? What about her husband? What about David's numbering of the people? How can you say that David only did that which was right in your eyes Lord?
Maybe it's because of passages like these where David wrote:
"I acknowledged my sin to you, and I did not cover my iniquity; I said, 'I will confess my transgressions to the Lord, and you forgave the iniquity of my sin. Selah" (Psa 32:1–5 ESV)
"He does not deal with us according to our sins, nor repay us according to our iniquities. For as high as the heavens are above the earth, so great is his steadfast love toward those who fear him; as far as the east is from the west, so far does he remove our transgressions from us." (Psa 103:10–12 ESV)
It is wonderful to realize, that no matter what we have done, if we truly repent of our sin, and confess it to the Lord, it will not be held against us. How is this possible? It is possible, because Jesus took the punishment for David's sin, and for the sin of all who would ever trust in Him! Now because of what Jesus did, it is possible for us to be looked upon by God as perfectly righteous!
"For our sake he made him to be sin who knew no sin, so that in him we might become the righteousness of God." (2 Cor 5:21 ESV)
Child of God have you fallen into sin? "If we confess our sins, He is faithful and just to forgive us our sins, and cleanse us from all unrighteouseness." (I John 1:9)
If you are trusting in Christ, and have confessed your sin to Him, then God's assesment of David is God's assesment of you!