Is it necessary to add a @ in front of an SqlParameter name?

According to the documentation, the name must start with an @:

The ParameterName is specified in the form @paramname.

According to the source code (have a look at SqlCommand and SqlParameter.ParameterNameFixed in the reference source), an @ is added automatically, if needed.

So yes, it works, but it’s an undocumented feature. Best practice recommends that you do not rely on this and manually prefix your parameter name with an @.

Leave a Comment