以下是我的数据来源。
<asp:SqlDataSource ID="getbyviews" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectAntiFrack %>"
SelectCommand="SELECT [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews]
FROM [ArticlesTBL]
WHERE ([ArticlePublished] = @ArticlePublished)
ORDER BY [ArticleViews] DESC">
<SelectParameters>
<asp:Parameter DefaultValue="True" Name="ArticlePublished" Type="Boolean" />
</SelectParameters>
</asp:SqlDataSource>
有没有办法操纵select语句只能获得5个最高结果?或者这可以在C#中完成吗? 我的数据源将在稍后用于填充列表视图。
答案 0 :(得分:3)
只需使用TOP 5
:
SELECT TOP 5 [ArticleID], [ArticleTitle], [ArticlePublished], [ArticleViews]
FROM [ArticlesTBL]
WHERE ([ArticlePublished] = @ArticlePublished)
ORDER BY [ArticleViews] DESC