这是个例子:该例子使用 AbsolutePage、PageCount 和 PageSize 属性,以每次五个记录的方式显示雇员表中的姓名和受雇日期。Public Sub AbsolutePageX()
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim strMessage As String
Dim intPage As Integer
Dim intPageCount As Integer
Dim intRecord As Integer ' 使用客户端游标为雇员表打开一个记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstEmployees = New ADODB.Recordset
' 使用客户端游标激活 AbsolutePosition 属性。
rstEmployees.CursorLocation = adUseClient
rstEmployees.Open "employee", strCnn, , , adCmdTable
' 显示姓名和受雇日期,每次五个记录。
rstEmployees.PageSize = 5
intPageCount = rstEmployees.PageCount
For intPage = 1 To intPageCount
rstEmployees.AbsolutePage = intPage
strMessage = ""
For intRecord = 1 To rstEmployees.PageSize
strMessage = strMessage & _
rstEmployees!fname & " " & _
rstEmployees!lname & " " & _
rstEmployees!hire_date & vbCr
rstEmployees.MoveNext
If rstEmployees.EOF Then Exit For
Next intRecord
MsgBox strMessage
Next intPage
rstEmployees.CloseEnd Sub
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim strMessage As String
Dim intPage As Integer
Dim intPageCount As Integer
Dim intRecord As Integer ' 使用客户端游标为雇员表打开一个记录集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstEmployees = New ADODB.Recordset
' 使用客户端游标激活 AbsolutePosition 属性。
rstEmployees.CursorLocation = adUseClient
rstEmployees.Open "employee", strCnn, , , adCmdTable
' 显示姓名和受雇日期,每次五个记录。
rstEmployees.PageSize = 5
intPageCount = rstEmployees.PageCount
For intPage = 1 To intPageCount
rstEmployees.AbsolutePage = intPage
strMessage = ""
For intRecord = 1 To rstEmployees.PageSize
strMessage = strMessage & _
rstEmployees!fname & " " & _
rstEmployees!lname & " " & _
rstEmployees!hire_date & vbCr
rstEmployees.MoveNext
If rstEmployees.EOF Then Exit For
Next intRecord
MsgBox strMessage
Next intPage
rstEmployees.CloseEnd Sub
你说的分页 是如何做啊?能写出具体的SQL语句参考吗?T2(無藥可救):
“set Rowrount=100 加到 SQL 語句中 ”可是如果用Access做数据库的话,在SQL语句里好像没有这个的吧?能写出具体的SQL语句吗:huanggx(大侠) :
你的例子我稍后研究一下,不过你出了这么多力,不管结果如何我都会加分给你。谢谢各位,有帮助的我都会加分。
select top 100 * from YourTable where field1 = arg1;
select 10 persent * from YourTable where field1 = arg1;
这可以使读如内存的记录较少。缺点是后继的无法解决。
当然要加快速度,还是得通过建立索引等方法。
当然还可以通过ID来分别读取。
select * from YourTable where ID > 0 and ID < 101; '前100条
select * from YourTable where ID > 100 and ID < 201; '后100条
………………………………………………………………………………
select top 100 * from YourTable;//第一个100条
rs.movelast
ID = rs("ID")
"select top 100 * from YourTable where ID > " & ID ;//第二个100条
rs.movelast
ID = rs("ID")
"select top 100 * from YourTable where ID > " & ID ;//第三个100条
………………………………………………………………………………
呵呵
好象这样就可以了啊