I Samuel 23:1-14 (excerpts in order to save space) - Then they told David, saying, Behold, the Philistines fight against Keilah...Therefore David inquired of the LORD, saying, Shall I go and smite these Philistines? And the LORD said unto David, Go, and smite the Philistines, and save Keilah. And David's men said unto him, Behold, we be afraid here in Judah: how much more then if we come to Keilah against the armies of the Philistines? Then David enquired of the LORD yet again. And the LORD answered him and said, Arise, go down to Keilah; for I will deliver the Philistines into thine hand. So David and his men went to Keilah, and fought with the Philistines, and brought away their cattle, and smote them with a great slaughter. So David saved the inhabitants of Keilah...And it was told Saul that David was come to Keilah. And Saul said, God hath delivered him into mine hand; for he is shut in, by entering into a town that hath gates and bars...Then said David, O LORD God of Israel, thy servant hath certainly heard that Saul seeketh to come to Keilah, to destroy the city for my sake. Will the men of Keilah deliver me up into his hand? will Saul come down, as thy servant hath heard?...And the LORD said, He will come down...And the LORD said, They will deliver thee up. Then David and his men, which were about six hundred, arose and departed out of Keilah, and went whithersoever they could go...And David abode in the wilderness in strong holds, and remained in a mountain in the wilderness of Ziph. And Saul sought him every day, but God delivered him not into his hand.
During the period in which David was avoiding King Saul, David received a message that the Philistines were attacking the city of Keilah (a city of the tribe of Judah, David's tribe; Josh. 15:44). David inquired of the Lord whether to go up and fight against the Philistines. God gave a definite message that he should go. So it is quite evident that the action of David and his men to go to this city and fight was the will of God. David was doing God's will. The events that follow teach us some lessons about doing God's will.
Verse 3 - Doing God's will does not guarantee fearlessness. Though the men of David knew it was God's will, they were still afraid. They needed reassuring (v. 4).
Verses 3,4 - Doing God's will does not mean we will go where we want to go. Sometimes faith requires us to step out and go places that would not be those of our preference.
Verses 7-13 - Doing God's will does not exempt us from problems and troubles. David and his men had just fulfilled what God told them to do. Then they heard that Saul knew they were shut up in a city and was planning to come after them.
Verse 12 - Doing God's will does not mean we will be appreciated. Though David and his men had just delivered the citizens of Keilah (of his own tribe) from the Philistines, these same citizens would have no qualms about delivering them up to Saul.
Verses 5,14 - Doing God's will DOES promise us ultimate success. David was never captured by Saul and God set him on the throne as He had promised through His prophet Samuel. (cf. I Samuel 16:13; II Kings 2:11; Romans 8:28; et al.).