King David was shown as a good and just king in his rule and is very highly regarded for it. Jesus was a descendent of King David. Most importantly David listened to God and did as He wished. Ahab was less known because he wasn't as faithful. Ahab did not listen to God's instructions and ended up paying the price.
The story about King David's rule had his son, Absalom, revolting against him. King David raised an army and set out of Jerusalem to fight him. David was fair to his men and followed the wishes of God. He commanded his army to not kill his son, Absalom. David defeated Absalom's army in the forest near Mahanaim, where 20,000 men died. While Absalom was riding away, his hair got stuck in a branch and he was hung by his hair. Joab, one of David's officers, drove a pike through Absalom's heart. When David was told of the "good news" he was very upset.
King Ahab was successful in terms of battle. He defeated Ben-hadad in 2 major battles. It was only the Lord's guidance that one him those battles however. The Lord advised him of those battles, and how he would go about winning those battles. Ahab also seized Naboth's vineyard against the Lord's wishes. Naboth resisted, so Ahab had him stoned to death. The Lord sent Elijah the Tishbite to deliver a message to Ahab, condemning him for Naboth's murder, and saying that he shall die in the same spot that Naboth has, and that dogs will lap up his blood. His line is also condemned to a similar fate. Ahab humbled himself, and God decided not to bring evil in his time, but to his son instead.
Ahab was a bad king in the eyes of the Deuteronomic historian because of his lack of faith. Although he was a successful king in terms of battle and his rule, he didn't keep the Lord's covenant. Although he repented toward the end of his life, it was too little too late. A king is judged by his faith in God and the keeping of his covenant. Ahab sinned greatly, and ended up paying the price.