There is no way that we can count on ourselves to walk uprightly before God. As humans, we trip, stumble, and fall. God our Father has to pick us up and set us back on our feet. There is no other alternative. We cannot get back on our feet by ourselves.
David was right to cry out to God and honestly admit his sin, to call on God to wash him and make him clean. We cannot rely upon the past inventory of good deeds that we think we can remember, because God knows us better than we know ourselves. Why not then be like the tax collector in the parable and stand off to one side, beat our breast, and cry out to our Lord who died on the cross for our sin, "God be merciful to me a sinner!" (Luke 18:13)?
Jesus has given us this assurance through his word, that he is there as the good shepherd to pick us up when we fall, to lead us to the green pastures and the still waters. All we have to do is be honest with God, and he will do it.
"I am the gate. Those who come in by me will be saved; they will come in and go out and find pasture. . . . I am the good shepherd, who is willing to die for the sheep. When the hired man, who is not a shepherd and does not own the sheep, sees a wolf coming, he leaves the sheep and runs away; so the wolf snatches the sheep and scatters them. I am the good shepherd. . . . I know my sheep and they know me. And I am willing to die for them." (John 10:9, 11-12, 14-15)
"We have fallen, but we will rise again. We are in darkness now, but the Lord will give us light." (Micah 7:8)