Sometimes this happens and it's appropriate. For instance, if someone asks:
How do I drive a nail with a screwdriver?
it might be appropriate to say
Actually, it's better to use a hammer for this. You will break your screwdriver if you drive enough nails with it, and you are likely to ruin your nails or your wall.
You don't always know what you need, and a lot of times the proposed method is either inappropriate, stupid, or dangerous. Questioning the validity of a question in an answer is appropriate if:
1 - It's polite
2 - The answerer explains WHY the premise of the question is incorrect
3 - They provide an alternate solution or path
In your case, the answer was none of these (arguably he did a little of #2), and it would be appropriate to flag it for moderator attention as
not an answer.
See also The XY Problem which is often related to this.