As king, David was in a position to give orders and know that they would be carried out. When David saw Bathsheba, he was attracted to her because "the woman was very beautiful." (2 Samuel 11:2) Bathsheba's husband Uriah was away from home when this happened, fighting with King David's troops against the enemy Ammonites.
King David manipulated Uriah's orders, bringing him home from the battle in hopes that he would spend time with Bathsheba so that the pregnancy would appear to be his. When Uriah refused to visit his home while his fighting companions were away from theirs. Finally, King David sent Uriah back to the battle, giving him a letter to be delivered to Joab, the commander. The letter read, "Set Uriah in the forefront of the hardest fighting, and then draw back from him, that he may be struck down, and die." (2 Samuel 11:15)
As commander of the troops, Joab should have been the one to decide the placement of troops. King David's specific orders for the placement of one particular fighter ignored Joab's strategic plans, forcing Joab to place Uriah in an unsupportable position to cover the king's indiscretion with Bathsheba. The only reason for the crime against Uriah was King David's need to hide his crime against Uriah's wife, Bathsheba.