在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
发布评论