You generally want to state what problem you had and not just post the code you tried. I see two problems though:
1) You always use result and not the index of the statement. Which means this runs the select statement repeatedly.
2) The statements could be run out of order if you have a select after the insert/update.
I noticed you've fixed the result bug pointed out by Jeanne in your post. To prevent a confusion, please refrain from editing posts others have already replied to in a manner that makes the replies meaningless; or at least put a note into the edited post so that the changes are obvious. Thanks.