<%@ Import Namespace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDb" %>
<html>
<head runat=server>
<title></title>
</head>
<body>
<%
Dim objCon As OleDbConnection
Dim objDataAdapter As OleDbDataAdapter
Dim strDbCon As String
Dim intFCount, intI, intJ As Integer
Dim pageNo, pageSize As String
Dim intPageNo, intPageSize, intStartRec, intStopRec As Integer
Dim intMaxPageCount, intMaxRec As Integer
' 取得目前資料表記錄的頁數
pageNo = Request.QueryString("PageNo")
If pageNo = "" Then
intPageNo = 1
Else
intPageNo = Convert.ToInt32(pageNo)
End If
' 取得每一頁顯示的記錄數
pageSize = Request.QueryString("PageSize")
If pageSize = "" Then
intPageSize = 2
Else
intPageSize = Convert.ToInt32(pageSize)
End If
' OLEDB提供者字串
strDbCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.Mappath("Users.mdb")
' 建立Connection物件
objCon = New OleDbConnection(strDbCon)
' 建立DataAdapter物件
objDataAdapter = New OleDbDataAdapter("Select * From Users", objCon)
' 建立DataSet物件
Dim objDataSet As DataSet = New DataSet()
' 將取得的記錄資料填入DataSet物件
objDataAdapter.Fill(objDataSet, "Users")
' 最大的記錄數
intMaxRec = objDataSet.Tables("Users").Rows.Count
' 是否有查詢到記錄
If intMaxRec > 0 Then
' 計算開始的記錄
intStartRec = intPageSize * (intPageNo - 1) + 1
' 計算結束的記錄
intStopRec = intStartRec + intPageSize - 1
If intStopRec >= intMaxRec Then
intStopRec = intMaxRec - 1
End If
' 計算頁數
intMaxPageCount = intMaxRec \ intPageSize
If (intMaxRec MOD intPageSize) > 0 Then
intMaxPageCount = intMaxPageCount + 1
End If
Dim objColumn As DataColumn
Response.Write("<table border=1><tr>")
' 顯示資料庫的欄位名稱
For Each objColumn in objDataSet.Tables("Users").Columns
Response.Write("<td><b>" & objColumn.ColumnName & "</b></td>")
Next
intFCount = objDataSet.Tables("Users").Columns.Count
Response.Write("</tr>")
Dim objRow As DataRow
' 使用迴路顯示記錄
intJ = intStartRec
Do
objRow = objDataSet.Tables("Users").Rows(intJ - 1)
Response.Write("<tr>")
For intI = 0 To intFCount - 1
If objRow.IsNull(intI) = False Then
Response.Write("<td valign=""top"">" & objRow(intI) & "</td>")
Else
Response.Write("<td valign=""top"">---</td>")
End If
Next
Response.Write("</tr>")
intJ = intJ + 1
Loop Until intJ > intStopRec
Response.Write("</table>")
Response.Write("一共有" & intMaxRec & "筆<br>")
' 目前的頁數
Response.Write("目前為第" & intPageNo & "頁/總共有" & intMaxPageCount & "頁<br>")
' 建立數字的超連結
Dim strURL, intPreviousPageNo, intNextPageNo
For intI = 1 To intMaxPageCount
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intI
strURL = strURL & "&PageSize=" & intPageSize & "'>" & intI & "</a>"
Response.Write(strURL & " ")
If intI mod 10 = 0 Then
Response.Write("<br>")
End If
next
' 上一頁的超連結
intPreviousPageNo = intPageNo - 1
If intPreviousPageNo > 0 Then
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intPreviousPageNo
strURL = strURL & "&PageSize=" & intPageSize & "'>上一頁</a>"
Response.Write(strURL & " ")
End If
' 下一頁的超連結
intNextPageNo = intPageNo + 1
If intNextPageNo <= intMaxPageCount Then
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intNextPageNo
strURL = strURL & "&PageSize=" & intPageSize & "'>下一頁</a>"
Response.Write(strURL & " ")
End If
End If
objCon.Close() ' 關閉資料庫連結
%>
</body>
</html>
<%@ Import NameSpace="System.Data.OleDb" %>
<html>
<head runat=server>
<title></title>
</head>
<body>
<%
Dim objCon As OleDbConnection
Dim objDataAdapter As OleDbDataAdapter
Dim strDbCon As String
Dim intFCount, intI, intJ As Integer
Dim pageNo, pageSize As String
Dim intPageNo, intPageSize, intStartRec, intStopRec As Integer
Dim intMaxPageCount, intMaxRec As Integer
' 取得目前資料表記錄的頁數
pageNo = Request.QueryString("PageNo")
If pageNo = "" Then
intPageNo = 1
Else
intPageNo = Convert.ToInt32(pageNo)
End If
' 取得每一頁顯示的記錄數
pageSize = Request.QueryString("PageSize")
If pageSize = "" Then
intPageSize = 2
Else
intPageSize = Convert.ToInt32(pageSize)
End If
' OLEDB提供者字串
strDbCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.Mappath("Users.mdb")
' 建立Connection物件
objCon = New OleDbConnection(strDbCon)
' 建立DataAdapter物件
objDataAdapter = New OleDbDataAdapter("Select * From Users", objCon)
' 建立DataSet物件
Dim objDataSet As DataSet = New DataSet()
' 將取得的記錄資料填入DataSet物件
objDataAdapter.Fill(objDataSet, "Users")
' 最大的記錄數
intMaxRec = objDataSet.Tables("Users").Rows.Count
' 是否有查詢到記錄
If intMaxRec > 0 Then
' 計算開始的記錄
intStartRec = intPageSize * (intPageNo - 1) + 1
' 計算結束的記錄
intStopRec = intStartRec + intPageSize - 1
If intStopRec >= intMaxRec Then
intStopRec = intMaxRec - 1
End If
' 計算頁數
intMaxPageCount = intMaxRec \ intPageSize
If (intMaxRec MOD intPageSize) > 0 Then
intMaxPageCount = intMaxPageCount + 1
End If
Dim objColumn As DataColumn
Response.Write("<table border=1><tr>")
' 顯示資料庫的欄位名稱
For Each objColumn in objDataSet.Tables("Users").Columns
Response.Write("<td><b>" & objColumn.ColumnName & "</b></td>")
Next
intFCount = objDataSet.Tables("Users").Columns.Count
Response.Write("</tr>")
Dim objRow As DataRow
' 使用迴路顯示記錄
intJ = intStartRec
Do
objRow = objDataSet.Tables("Users").Rows(intJ - 1)
Response.Write("<tr>")
For intI = 0 To intFCount - 1
If objRow.IsNull(intI) = False Then
Response.Write("<td valign=""top"">" & objRow(intI) & "</td>")
Else
Response.Write("<td valign=""top"">---</td>")
End If
Next
Response.Write("</tr>")
intJ = intJ + 1
Loop Until intJ > intStopRec
Response.Write("</table>")
Response.Write("一共有" & intMaxRec & "筆<br>")
' 目前的頁數
Response.Write("目前為第" & intPageNo & "頁/總共有" & intMaxPageCount & "頁<br>")
' 建立數字的超連結
Dim strURL, intPreviousPageNo, intNextPageNo
For intI = 1 To intMaxPageCount
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intI
strURL = strURL & "&PageSize=" & intPageSize & "'>" & intI & "</a>"
Response.Write(strURL & " ")
If intI mod 10 = 0 Then
Response.Write("<br>")
End If
next
' 上一頁的超連結
intPreviousPageNo = intPageNo - 1
If intPreviousPageNo > 0 Then
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intPreviousPageNo
strURL = strURL & "&PageSize=" & intPageSize & "'>上一頁</a>"
Response.Write(strURL & " ")
End If
' 下一頁的超連結
intNextPageNo = intPageNo + 1
If intNextPageNo <= intMaxPageCount Then
strURL = "<a href='Ch10-4-2.aspx?PageNo=" & intNextPageNo
strURL = strURL & "&PageSize=" & intPageSize & "'>下一頁</a>"
Response.Write(strURL & " ")
End If
End If
objCon.Close() ' 關閉資料庫連結
%>
</body>
</html>