【问题标题】:Changing TOP rows parameter from code behind从后面的代码更改 TOP rows 参数
【发布时间】:2013-08-03 02:46:58
【问题描述】:

我知道我们可以在 C# 代码中使用 SqlCommand.Parameters.AddWithValue("@xyz",xyz) 为查询 Select * from abc where xyz=@xyz 添加参数。但是是否可以更改查询的顶行参数,例如Select TOP @rows * from abc where xyz=@xyz,例如SqlCommand.Parameters.AddWithValue("@rows",32)

因为每当我尝试它时,它都会向我显示这个异常:Incorrect syntax near '@rows'.

【问题讨论】:

  • 不属于语法错误。

标签: c# .net sql-server parameters code-behind


【解决方案1】:

您可以明确地将整数传递到顶部子句。你应该可以做这样的事情。

select top (@Rows) *
from dbo.MyTable
order by something

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 2011-04-16
    • 2016-05-02
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    相关资源
    最近更新 更多