如何显示上一页,下一页

lxf200409 2004-11-28 10:52:07
如何将通过两个按钮来进行记录的上一页和下一页的显示,一页显示10条记录,现在表中定义了49记录
另外用一个文本框输入页号,然后显示第几页的记录,解决问题的50分
...全文
179 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
True1024 2004-11-30
  • 打赏
  • 举报
回复
用分页做。
lxf200409 2004-11-30
  • 打赏
  • 举报
回复

谢谢
lxcc 2004-11-29
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3400/3400520.xml?temp=2.529544E-02

http://community.csdn.net/Expert/topic/3181/3181711.xml?temp=.4685785
Abyss-Xu 2004-11-29
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3400/3400520.xml?temp=2.529544E-02 这个说的比较好
容易看的懂
Option Explicit
Dim conn As ADODB.Connection
Dim lCurrentPage As Long

Private Sub cmdNext_Click()
lCurrentPage = lCurrentPage + 1
Call Loadcontrol(lCurrentPage)
End Sub

Private Sub cmdPrevious_Click()
If lCurrentPage > 1 Then
lCurrentPage = lCurrentPage - 1
Call Loadcontrol(lCurrentPage)
End If
End Sub

Private Sub Form_Load()

Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test2000.mdb;"

lCurrentPage = 1
Call Loadcontrol(lCurrentPage)

End Sub
Private Sub Loadcontrol(lPage As Long)
Dim adoPrimaryRS As ADODB.Recordset
Dim lPageCount As Long
Dim nPageSize As Integer
Dim lCount As Long

'每页显示的纪录
nPageSize = 10
Set adoPrimaryRS = New ADODB.Recordset
adoPrimaryRS.Open "select * from numbers", conn, adOpenStatic, adLockOptimistic

adoPrimaryRS.PageSize = nPageSize
'页数
lPageCount = adoPrimaryRS.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End If

adoPrimaryRS.AbsolutePage = lCurrentPage
'定义另一个记录集
Dim objrs As New ADODB.Recordset
'添加字段名称
For lCount = 0 To adoPrimaryRS.Fields.Count - 1
objrs.Fields.Append adoPrimaryRS.Fields(lCount).Name, adVarChar, adoPrimaryRS.Fields(lCount).DefinedSize
Next
'打开记录集
objrs.Open
'将指定记录数循环添加到objrs中
For lCount = 1 To nPageSize
objrs.AddNew
objrs!id = adoPrimaryRS!id
objrs!anumber = adoPrimaryRS!anumber
adoPrimaryRS.MoveNext
Next
'绑定
Set DataGrid1.DataSource = objrs

'显示页数
txtPage = lPage & "/" & adoPrimaryRS.PageCount
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Not conn Is Nothing Then
conn.Close
End If
Set conn = Nothing
End Sub
mingday 2004-11-29
  • 打赏
  • 举报
回复
用rs.pagesize
fishmans 2004-11-29
  • 打赏
  • 举报
回复
记录集不大的话可以用recordset.move

如:
第一页:
recordset.movefirst
for i=0 to 9
..........
next
第二页:
recordset.movefirst
recordset.move 10
for i=0 to 9
..........
next
danielinbiti 2004-11-28
  • 打赏
  • 举报
回复
收入的sql存储过程,

CREATE PROCEDURE p_GetRecord
@tblName varchar(255), -- 表名
@tblfldName varchar(21), --字段名前缀
@fldName varchar(255), -- 字段名
@SelectfldName varchar(1000),--选择的字段
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@IsCount Tinyint= 0, -- 返回记录总数, 非 0 值则返回
@OrderType Tinyint = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1000) = '' -- 查询条件 (注意: 不要加 where)
AS
set nocount on
declare @strSQL varchar(6000) -- 主语句
declare @strTmp varchar(100) -- 临时变量
declare @strOrder varchar(400) -- 排序类型

if @OrderType != 0
begin
set @strTmp = "<(select min"
set @strOrder = " order by " + @tblfldName+".["+@fldName +"] desc"
end
else
begin
set @strTmp = ">(select max"
set @strOrder = " order by " + @tblfldName+".["+@fldName +"] asc"
end

set @strSQL = "select top " + str(@PageSize) + " "+@SelectfldName+" from "
+ @tblName +" where " + rtrim(@tblfldName)+".["+@fldName +"] " + @strTmp
+ " tblTmp.["+ @fldName + "] from (select top " + str((@PageIndex-1)*@PageSize) + " "
+ rtrim(@tblfldName)+".["+@fldName +"] from " + @tblName + " " + @strOrder + ") as tblTmp) "
+ @strOrder

if @strWhere != '' --如果有where条件子句
set @strSQL = "select top " + str(@PageSize) + " "+@SelectfldName+" from "
+ @tblName + " where " + @tblfldName+".["+@fldName +"] " + @strTmp
+ " tblTmp.["+ @fldName + "] from (select top " + str((@PageIndex-1)*@PageSize) + " "
+ @tblfldName+".["+@fldName +"] from " + @tblName + " where " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder

if @PageIndex = 1 --如果是第一页
begin
set @strTmp = ""
if @strWhere != ''
set @strTmp = " where " + @strWhere

set @strSQL = "select top " + str(@PageSize) +" "+@SelectfldName+ " from "
+ @tblName + @strTmp + " " + @strOrder
end

if @IsCount != 0 --查询记录总数
begin
set @strSQL = "select count(*) as Total from [" + @tblName + "]"
if @strWhere!=''
set @strSQL="select count(*) as Total from [" + @tblName + "]"
+" where "+ @strWhere
end
exec (@strSQL)
GO
vblau 2004-11-28
  • 打赏
  • 举报
回复
没有ID号也可以编辑进去嘛
aohan 2004-11-28
  • 打赏
  • 举报
回复
如果有ID号的

则这样来实现

第一页
select * from table where id between 1 and 10

第二页

select * from table where id between 11 and 20

……



7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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