0

是否可以按 LastActivityDate 的顺序显示此数据

<asp:AccessDataSource ID="usage_info_DS" runat="server" DataFile="~/App_Data/ASPNetDB.mdb" SelectCommand="SELECT aspnet_Users.UserName, aspnet_Users.LastActivityDate, aspnet_Membership.LastLoginDate FROM (aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId) WHERE (aspnet_Membership.UserId <> 100) AND (aspnet_Membership.UserId IN (SELECT UserId FROM aspnet_UsersInRoles WHERE (RoleId = (SELECT RoleId FROM aspnet_Roles WHERE (RoleName = ?)))))">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="?" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:AccessDataSource>

干杯罗斯

4

2 回答 2

0

在 sql 语句中使用order by 子句。所以你的查询应该是:

SELECT 
aspnet_Users.UserName, 
aspnet_Users.LastActivityDate, 
aspnet_Membership.LastLoginDate 
FROM 
        (aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId) 
WHERE   
        (aspnet_Membership.UserId <> 100) 
        AND (aspnet_Membership.UserId IN (SELECT UserId FROM aspnet_UsersInRoles 
                                          WHERE (RoleId = (SELECT RoleId FROM aspnet_Roles WHERE (RoleName = ?)))))
order by 2;

2 指定应用排序依据的列,也可以使用列名aspnet_Users.LastActivityDate

编辑:

如果要在结果集顶部获取最新日期,请使用:

order by 2 desc;
于 2012-07-12T06:01:14.587 回答
0

尝试

<asp:AccessDataSource ID="usage_info_DS" runat="server" DataFile="~/App_Data/ASPNetDB.mdb" SelectCommand="SELECT aspnet_Users.UserName, aspnet_Users.LastActivityDate, aspnet_Membership.LastLoginDate FROM (aspnet_Membership INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId) WHERE (aspnet_Membership.UserId <> 100) AND (aspnet_Membership.UserId IN (SELECT UserId FROM aspnet_UsersInRoles WHERE (RoleId = (SELECT RoleId FROM aspnet_Roles WHERE (RoleName = ?))))) order by aspnet_Users.LastActivityDate">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="?" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:AccessDataSource>
于 2012-07-12T05:54:19.473 回答