How to set unnamed SQL parameters in SqlCommand

2020-03-24 04:55发布

If I add unnamed parameters to my SqlCommand, how do I set the parameter values, on the SqlCommand?

I have no problems when I use named parameters, where I can just do SqlCommand.Parameters.AddWithValue().

Example:

Select * from sometable where SomeValue=? and AnotherValue=?

2条回答
戒情不戒烟
2楼-- · 2020-03-24 05:07

Use ADODBConnection and ADODBCommand instead of SQL versions.

查看更多
Luminary・发光体
3楼-- · 2020-03-24 05:24

With ADO.NET against SQL Server, you cannot use those ? for parameters - you always have to use @paramName approach.

The ? for unnamed parameters is an ODBC "left-over" but not supported in ADO.NET when using SQL Server (not sure about MS-Access)

查看更多
登录 后发表回答