Using parametrized query is quite a right idea, and the code shown is not. Please see:
http://msdn.microsoft.com/en-us/library/ff648339.aspx[
^].
See also my past answers:
EROR IN UPATE in com.ExecuteNonQuery();[
^],
hi name is not displaying in name?[
^].
The query composed by concatenation with strings taken from UI. Not only repeated string concatenation is inefficient (because strings are
immutable; do I have to explain why it makes repeated concatenation bad?), but yes, way more important issue is that it opens the doors to
SQL injection. The user can write anything in the UI, including some SQL fragment. Are you getting the idea? This is how:
http://xkcd.com/327.
—SA