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

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 @.

 

posted @ 2021-02-02 15:14  ChuckLu  阅读(57)  评论(0编辑  收藏  举报