How to sort the record by using SQL command?
We can sort the record by using SQL command.
The ASP codes are written and described as below:
<% Set conn = Server.CreateObject("Adodb.Connection") conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db1.mdb") Set rs = Server.CreateObject("Adodb.Recordset") strSQL = "SELECT * FROM Member ORDER BY Location" 'Generate a SQL command to sort the Location fields in Ascending order. rs.Open strSQL,conn,1,3 'Use the SQL to generate the Recordset If rs.EOF Then 'If Eof is True; that means is empty recordset %> <% Else Do while Not rs.eof %> <% rs.movenext Loop End If rs.Close Set rs = Nothing %>
No member...
<%=rs("MemID")%> <%=rs("MemberName")%> <%=rs("Location")%>
If you need to perform the descending order, you can add a word "DESC" in the back of SQL command, such as:
SELECT * FROM Member ORDER BY Location DESC
No comments:
Post a Comment