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

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

问题描述

如果我添加未命名的参数,以我的的SqlCommand ,我怎么设置的参数值,中SqlCommand?

我没有问题,当我使用命名参数,在那里我可以做 SqlCommand.Parameters.AddWithValue()

例如:

  SELECT * FROM sometable哪里someValue中=?和AnotherValue =?
 

解决方案

通过ADO.NET对SQL Server,您不能使用那些 的参数 - ?你总是要使用 @paramName 办法。

未命名的参数是一个ODBC遗留,而是使用SQL Server(不知道MS-接入)

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

解决方案

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)

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

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