从ASP.NET中的代码中的变量为SQL Server中的Select Top设置变量(Set variable for Select Top in SQL Server from a variabl

编程入门 行业动态 更新时间:2024-10-27 00:33:51
从ASP.NET中的代码中的变量为SQL Server中的Select Top设置变量(Set variable for Select Top in SQL Server from a variable in code behind in ASP.NET)

在asp.net中,我想从一个sql server数据库中选择Top x,其中x是在后面的代码(cs)中以编程方式设置的。

从后面的代码绑定一个字符串以传递给SqlDataSource控件中的SelectCommand的数据似乎不起作用。

有没有办法将代码中的变量绑定到aspx SqlDataSource的SelectCommand,还是有另一种方法?

In asp.net, I want to select the Top x from a sql server database where x is set programattically in the code behind (cs).

Data binding a string from the code behind to pass to the SelectCommand in the SqlDataSource control doesn't seem to be working.

Is there a way to bind a variable from the code to the SelectCommand of the aspx SqlDataSource, or is there another way?

最满意答案

假设您在前端声明了一个SQL数据源。

<asp:SqlDataSource ID="SqlDataSource" runat="server"> </asp:SqlDataSource>

在页面后面的代码中添加相应的事件代码,以编程方式设置SQL数据源命令。

string sTop = "10"; SqlDataSource.SelectCommand = "SELECT Top " + sTop + " * FROM dbo.clients";

另外,请考虑使用DataTable或DataSet。

Assuming you have a SQL data source declared in the front end.

<asp:SqlDataSource ID="SqlDataSource" runat="server"> </asp:SqlDataSource>

In the code behind of your page add to the appropriate event code something like this to programmatically set the SQL data source command.

string sTop = "10"; SqlDataSource.SelectCommand = "SELECT Top " + sTop + " * FROM dbo.clients";

Also, consider using a DataTable or DataSet instead.

更多推荐

SelectCommand,SqlDataSource,代码,code,电脑培训,计算机培训,IT培训"/> <meta name

本文发布于:2023-08-02 01:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368026.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   量为   代码   SQL   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!