Many know that David sinned, and they wonder how he could be a man after God's own heart. As we look at the life of Solomon, his son, we quickly see a vast difference. Even though David didn't walk perfectly with the Lord, he never turned to idolatry. What about Solomon? 1 Kings 11:4 says that his wives turned away his heart after other gods. This is the difference between Solomon and David.
Let's think a little deeper about Solomon. God gave him great wisdom. He could make great decisions in political affairs. He didn't always make them in his personal/spiritual life. Read the following commentary on 1 Kings 11:6 from the Life Application Study Bible.
If Solomon was so wise, why did he turn from God? While Solomon applied his wisdom to political affaris, he did not always apply it to his spiritual life. He knew the right way to live, but he did not always have the will to do it. Many people have enough wisdom to know the difference between right and wrong, but they don't always do right. We need to develop not only the wisdom to do right, but the WILL to do it.
Sometimes knowing what is right is one thing, making right decisions is another. We need to dedicate ourselves to making the right decisions when we know what is right. Let's also remember the difference between David and Solomon is that David didn't allow anything to take the place of God as primary in importance in his life. Seek God first, then all these other things will be added unto you.Matthew 6:33