This question came to my mind a while back as i debated with so many in regards the faith, and heart of President George W. Bush ... "Does a man have to be perfect in all his ways to be concidered by God as one after His own heart"? ... Thank God the Bible says no, via the life of King David ...
2 Samuel 12:114
ADULTERY AND MURDER
David committed adultery with Bathsheba (2 Sam 11:4)
and murdered her husband Uriah the Hittite (11:1417; 12:9)
although David committed many sins during his life these two displeased God the most (I Kings 15:5)
NATHAN'S PARABLE (14)
the parable of Nathan is the most famous parable in the Old Testament (cf. Trees, Vineyard, Eagles, Boiling Pot)
the parable was designed to help David see himself as God saw him
apparently the Lord sent Nathan to David on the day Bathsheba gave birth to the baby (cf. 14, 18)about a year after he sinned
he was carnal and received divine discipline (serious illness) for a year before his confession if Psalm 32:35 refers to this incident
the rich man symbolizes David; the poor man symbolizes Uriah; the lamb symbolizes
the rich man owned "a very large number of sheep and cattle" (2), suggesting that he was a shepherd like David
the illustration is appropriate because David knew how attached one could become to a pet lamb since he had been a shepherd
the comparison of the baby ewe-lamb to a daughter who slept in the poor man's arms is a not-so-subtle reference to Bathsheba
the rich man stole the baby lamb to show hospitality to a guestbreaking the poor man's heart and the Mosaic Law
DAVID'S JUDGMENT OF THE RICH MAN AND SELF JUDGMENT (56)
in anger David first considered a punishment greater than the Law required:
literally, 'this man is a son of death' ("deserves to die," not the KJV's "shall surely die")
David pronounced a judgment in keeping with the Law: fourfold restitution for stealing a sheep (Exod 22:1)
the parable forced David to pass judgment on himself: when he condemned the rich man's sin he also condemned himself
if the rich man deserves to die for stealing a lamb, what does David deserve for adultery and murder?
INTERPRETATION OF THE PARABLE (79)
once he recognized the injustice in the parable, Nathan made the application to Davidtwo words: 'atah ha'ish 'You the man!'
it was not until Nathan said to David, "You are the man!" that David understood the meaning of the parable
the LORD described the great blessings He has given to David over the years:
position, protection, possessions, prestige, and privilege (78)all symbolized by the rich man's great wealth
Nathan enumerates David's sins against both God and man (9)
FUTURE DIVINE DISCIPLINE (1012)
David will now reap exactly what he has sown, and more of ita long and hard and bitter harvest
four of David's sons die prematurelyan unnamed son (12:18), Amnon (13:29), Absalom (18:1415), and Adonijah (I Kings 2:25)
David's sexual sins against Uriah will give rise to sexual sins committed by Absalom against Davidlex talionis (cf. 16:2122)
even though he confessed his sins he still received divine discipline for the rest of his life ("the sword shall never depart")
DAVID'S CONFESSION, GOD'S FORGIVENESS, AND COMMUTING OF THE DEATH PENALTY (13)
the full expression of David's confession can be studied in Psalm 51
adultery (Lev 20:10; Deut 22:22) and murder (Exod 21:1214; Lev 24:17, 21; Num 35:1621; Deut 19:1112) are capital offenses
God, the author of these laws and the supreme ruler of Israel, has the right to commute the death penalty if He wishes
IMMEDIATE DIVINE DISCIPLINE (14)
confession of sin and forgiveness does not always remove divine discipline: the baby will also die (cf. 18)
 And afterward they desired a king: and God gave unto them Saul the son of Cis, a man of the tribe of Benjamin, by the space of forty years.
 And when he had removed him, he raised up unto them David to be their king; to whom also he gave testimony, and said, I have found David the son of Jesse, a man after mine own heart, which shall fulfil all my will.
 Of this man's seed hath God according to his promise raised unto Israel a Saviour, Jesus.
Thank God i don't have to be perfect to be concidered a man after His own heart ... Just one who's trying his best to please Him ... And one quick to true, sorrowful repentance when i grieve Him ... And one that tho i may pay the consequences of my sin(s) via direct recompense or the stinging judgments of fellow men, still believe Him ... Just one like murdering, adultery commiting King David, thru whoms lineage God deemed it not robbery to birth His perfection, for our imperfection.
Though none of us deserve it ... We serve a gracious God ... Amen