Solomon was a great prophet and king, one of the greatest. He was wise and just. The Lord appeared to him multiple times (e.g., 1 Kings 9:2). Solomon was wealthy and well-respected by all. However, Solomon "loved many strange [non-covenant] women" (1 Kings 11:1). He had many wives and concubines. In his old age "his wives turned away his heart after other gods: and his heart was not perfect with the Lord his God, and it became as the heart of David his father" (JST 1 Kings 11:3-4). David's heart was not perfect either but he was repentant, or at least came across as repentant in the scriptures. Solomon worshiped false gods and forsook the Lord. The Lord then took away Solomon's blessings but retained some for his children (and so on) because of "David thy father's sake" (1 Kings 11:12). That's why, even though David did evil in the sight of the Lord, I believe his heart was more repentant than Solomon's was.
David's words comprise some of the most beautiful passages in the scriptures. His psalms contain beautiful words and beautiful themes. His words also focus heavily on the role of the Lord as Redeemer, largely because David is seeking forgiveness. Here are a few of his words: "For thou wilt light my candle: the Lord my God will enlighten my darkness." (Psalm 18:28). "The Lord is my light and my salvation; whom shall I fear? the Lord is the strength of my life; of whom shall I be afraid?" (Psalm 27:1). David also wrote some prophecies that told of events and teachings from the Savior's life: "My God, my God, why hast thou forsaken me? why art thou so far from helping me, and from the words of my roaring [the Lord as Lion is not an infrequent metaphor for the Savior].... For dogs have compassed me: the assembly of the wicked have inclosed me: they pieced my hands and my feet. I may tell all my bones: they look and stare upon me [foretelling the Savior on His way to Golgotha and upon the cross]. They part my garments among them, and cast lots upon my vesture" (Psalm 22:1,16-18). David's Psalms contain many more prophecies of the Savior, referring to Judas' betrayal (Psalm 41:9), cleansing the temple (Psalm 69:9), the suffering of the Savior in Gethsemane (Psalm 69:20), and how He was offered vinegar while on the cross (Psalm 69:21).
One of my favorite scriptures is found in the 84th psalm. "For a day in thy courts is better than a thousand. I had rather be a doorkeeper in the house of my God, than to dwell in the tents of wickedness. For the Lord God is a sun and shield: the Lord will give grace and glory: no good thing will he withhold from them that walk uprightly" (Psalm 84:10-11; emphasis added). David made mistakes. He made very grievous mistakes but he tried to do good. He is one character I admire and respect for many reasons, in spite of his faults.