一个有关数据库的问题,在用asp的时候发现的,以前没有注意!用ado访问大量纪录的数据库时的解决方法

shawls 2001-12-20 09:27:55
用ado访问大量纪录的数据库时的解决方法


我再用asp写一个留言版的时候,用到了向前向后翻页的属性

但是实现的时候,我不知道怎么实现

于是,就用了一个苯办法:计算是第几页,然后记录向后移动多少条

可是这样太消耗资源,速度也不快


请问,用ado访问sql server怎么定为第xx条纪录??


如果时开始得到是好办,可以用MaxRecords 限制,但是后面的呢?

...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
junglerover 2001-12-21
  • 打赏
  • 举报
回复
MSDN中的范例:

AbsolutePage、PageCount 和 PageSize 属性范例 (VB)

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

' Open a recordset using a client cursor
' for the employee table.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
Set rstEmployees = New ADODB.Recordset
' Use client cursor to enable AbsolutePosition property.
rstEmployees.CursorLocation = adUseClient
rstEmployees.Open "employee", strCnn, , , adCmdTable

' Display names and hire dates, five records
' at a time.
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.Close

End Sub

junglerover 2001-12-21
  • 打赏
  • 举报
回复
才发现原来ADODB.RecordSet对象是支持分页的。
你自己查一下MSDN吧。
直接设置PAGESIZE、AbsolutePage属性就可以了。
当然也可以设置AbsolutePosition属性。
shawls 2001-12-21
  • 打赏
  • 举报
回复
asp中不支持AbsolutePosition
shawls 2001-12-21
  • 打赏
  • 举报
回复


解决了使用.AbsolutePosition解决的
shawls 2001-12-20
  • 打赏
  • 举报
回复
to : tonton(tonton)


absoluteposition怎么用,可以告诉我语法吗?


shawls 2001-12-20
  • 打赏
  • 举报
回复


那么这个不能肯定呀!

例如,我如果现在再看第一页,然后我要马上跳转到第九页,那么,中间的id肯定是会有一定的差距的,而且,也不能得到第八页的最后一个id号码呀!


继续求教,不过,先加一点分,给后面的人

tonton 2001-12-20
  • 打赏
  • 举报
回复
可以用AbsolutePosition定位
junglerover 2001-12-20
  • 打赏
  • 举报
回复
例如,你的留言版帖子有一个ID,然后你每页是20行,
那么对于第一页,是
select top 20 * from table order by id
那么这一页生成时,你已经获得了第20条的ID。
那么对于第2页,就是
select top 20 * from table where id>第20条的ID order by id

依此类推。

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧