Expand|Select|Wrap|Line Numbers
- <%
- Option Explicit
- Const adOpenStatic = 3
- Const adLockReadOnly = 1
- Const adCmdText = &H0001
- Dim CONN_STRING
- CONN_STRING = "Driver={SQL Server};Server=.;Database=my_tables;uid=sa;pwd=travelzone"
- Dim iPageSize 'How big our pages are
- Dim iPageCount 'The number of pages we get back
- Dim iPageCurrent 'The page we want to show
- Dim strOrderBy 'A fake parameter used to illustrate passing them
- Dim sql 'SQL command to execute
- Dim conn 'The ADODB connection object
- Dim rs 'The ADODB recordset object
- Dim iRecordsShown 'Loop controller for displaying just iPageSize records
- Dim iFieldCount
- Dim iRecordCount
- Dim LoopRecordCount
- Dim pageNum
- Dim counter
- Dim markShowPage
- Dim I, J 'Standard looping var
- iPageSize = 10
- ' Retrieve page to show or default to 1
- If Request.QueryString("page") = "" Then
- iPageCurrent = 1
- Else
- iPageCurrent = CInt(Request.QueryString("page"))
- End If
- sql = "SELECT * from employee order by empid asc;"
- Set conn = Server.CreateObject("ADODB.Connection")
- conn.Open CONN_STRING
- ' Create recordset and set the page size
- Set rs = Server.CreateObject("ADODB.Recordset")
- rs.PageSize = iPageSize
- rs.CacheSize = iPageSize
- ' Open RS
- rs.Open sql, conn, adOpenStatic, adLockReadOnly, adCmdText
- ' Get the count of the pages using the given page size
- iPageCount = rs.PageCount
- iFieldCount = rs.Fields.Count
- iRecordCount = rs.RecordCount
- ' If the request page falls outside the acceptable range,
- ' give them the closest match (1 or max)
- If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
- If iPageCurrent < 1 Then iPageCurrent = 1
- If iPageCount = 0 Then
- Response.Write "No records found!"
- Else
- ' Move to the selected page
- rs.AbsolutePage = iPageCurrent
- response.write("<a href=logout.asp><h4 align=right>LogOut</h4></a>")
- response.write("<h3 align=center><u>Employee Details</u></h3>")
- ' Spacing
- Response.Write vbCrLf
- ' Continue with a title row in our table
- Response.Write "<table border=1 align=center>" & vbCrLf
- ' Show field names in the top row
- Response.Write vbTab & "<tr>" & vbCrLf
- For I = 0 To rs.Fields.Count - 1
- Response.Write vbTab & vbTab & "<th>"
- Response.Write rs.Fields(I).Name
- Response.Write "</th>" & vbCrLf
- Next 'I
- Response.Write vbTab & "</tr>" & vbCrLf
- ' Loop through our records and ouput 1 row per record
- iRecordsShown = 0
- Do While iRecordsShown < iPageSize And Not rs.EOF
- Response.Write vbTab & "<tr>" & vbCrLf
- For I = 0 To rs.Fields.Count - 1
- Response.Write vbTab & vbTab & "<td>"
- Response.Write rs.Fields(I)
- Response.Write "</td>" & vbCrLf
- Next 'I
- Response.Write vbTab & "</tr>" & vbCrLf
- ' Increment the number of records we've shown
- iRecordsShown = iRecordsShown + 1
- ' Can't forget to move to the next record!
- rs.MoveNext
- Loop
- ' All done - close table
- Response.Write "</table>" & vbCrLf
- End If
- response.write("<br><a href=employeeadd.asp><center><b><font color=green>Insert New Employee Details</font></b></center></a>")
- rs.Close
- Set rs = Nothing
- conn.Close
- Set conn = Nothing
- If iPageCurrent > 1 Then
- %>
- <a href="dbpaging_array.asp?page=<%= iPageCurrent - 1 %>"><< Prev</a>
- <%
- End If
- ' You can also show page numbers:
- For I = 1 To iPageCount
- If I = iPageCurrent Then
- %>
- <%= I %>
- <%
- Else
- %>
- <a href="dbpaging_array.asp?page=<%= I %>&order=<%= Server.URLEncode(strOrderBy) %>"><%= I %></a>
- <%
- End If
- Next 'I
- If iPageCurrent < iPageCount Then
- %>
- <a href="dbpaging_array.asp?page=<%= iPageCurrent + 1 %>&order=<%= Server.URLEncode(strOrderBy) %>">Next >></a>
- <%
- End If
- %>