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

前端 未结 4 1972
逝去的感伤
逝去的感伤 2020-11-27 08:19

In one of our application the parameters passed to a stored procedure in this way

Dim parm As New SqlParameter(\"searchText\", SqlDbType.VarChar)
parm.Direct         


        
4条回答
  •  佛祖请我去吃肉
    2020-11-27 08:48

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

提交回复
热议问题