How to set unnamed SQL parameters in SqlCommand

2020-03-24 05:07发布

问题:

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=?

回答1:

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)



回答2:

Use ADODBConnection and ADODBCommand instead of SQL versions.