如何在 SqlCommand 中设置未命名的 SQL 参数 [英] How to set unnamed SQL parameters in SqlCommand

查看:21
本文介绍了如何在 SqlCommand 中设置未命名的 SQL 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将未命名的参数添加到我的 SqlCommand,如何在 SqlCommand 上设置参数值?

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

我在使用命名参数时没有任何问题,我可以在其中执行 SqlCommand.Parameters.AddWithValue().

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

例子:

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

推荐答案

使用 ADO.NET 对抗 SQL Server,你不能使用那些 ? 作为参数 - 你总是必须使用 @paramName 方法.

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

未命名参数的 ? 是 ODBC遗留物",但在使用 SQL Server 时在 ADO.NET 中不受支持(不确定 MS-Access)

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

这篇关于如何在 SqlCommand 中设置未命名的 SQL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆