当前位置: 网学 > 编程文档 > VB > 正文

在vb中实现分页处理数据库

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式

作者:王勋

当数据量太大时,最好的办法是分页处理数据库中的数据  
''PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=E:\wang_xun\work\program\code\my_code\PrjPagination\bank.mdb;
Private pTotal As Integer
Private pCurrent As Integer
Private pCon As ADODB.Connection
Private pSize As Integer
Private Sub cmdFirst_Click()
pCurrent = 1
Call InitListViewData
Call InitDisplay
End Sub

Private Sub cmdGo_Click()
pCurrent = CInt(txtVal)
Call InitListViewData
Call InitDisplay
End Sub

Private Sub cmdLast_Click()
pCurrent = pTotal
Call InitListViewData
Call InitDisplay
End Sub

Private Sub cmdNext_Click()
pCurrent = pCurrent + 1
Call InitListViewData
Call InitDisplay
End Sub

Private Sub cmdPrevious_Click()
pCurrent = pCurrent - 1
Call InitListViewData
Call InitDisplay
End Sub

Private Sub Form_Load()
pSize = 50
Call AddHeader
Call MakeCon
Call InitListViewData
Call InitDisplay
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call ClearVar
End Sub

Sub ClearVar()
pTotal = 0
pCurrent = 0
Set pCon = Nothing
End Sub
Sub InitDisplay()
If pCurrent > pTotal Then
Call cmdFirst_Click
End If
Select Case pTotal
Case Is > 0
Call InitGoButton
Select Case pCurrent
Case 1
cmdFirst.Enabled = False
cmdLast.Enabled = True
cmdPrevious.Enabled = False
cmdNext.Enabled = True
Case Is < pTotal And pCurrent > 1
cmdFirst.Enabled = True
cmdLast.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
Case Is = pTotal
cmdFirst.Enabled = True
cmdLast.Enabled = False
cmdPrevious.Enabled = True
cmdNext.Enabled = False
Case Else
cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
End Select
Case Else
cmdFirst.Enabled = False
cmdLast.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdGo.Enabled = False
End Select
labPage.Caption = "共" & Str(pTotal) & "页,当前是第" & Str(pCurrent) & "页"
End Sub

Private Sub txtnum_Change()
pSize = CInt(txtnum.Text)
End Sub

Private Sub txtnum_ValidationError(InvalidText As String, StartPosition As Integer)
pSize = 1
End Sub

''Private Sub txtNum_Change()
''If Not (KeyAscii > 47 And KeyAscii < 58) Then
'' Beep
'' KeyAscii = 0
''End If
''End Sub

Private Sub txtVal_Change()
Call InitGoButton
End Sub

Private Sub txtVal_KeyPress(KeyAscii As Integer)
If Not (KeyAscii > 47 And KeyAscii < 58) Then
Beep
KeyAscii = 0
End If
End Sub
Sub InitGoButton()
If Len(txtVal) > 0 Then
If CInt(txtVal) > 0 And CInt(txtVal) <= pTotal Then
cmdGo.Enabled = True
Else
cmdGo.Enabled = False
End If
Else
cmdGo.Enabled = False
End If
End Sub
Sub AddHeader()
With lv
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "ID", 800
.ColumnHeaders.Add , , "名称", 2000
End With
End Sub
Sub MakeCon()
Dim a As New ADODB.Connection
''a.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=E:\wang_xu
  • 下一篇资讯: VB也能访问内存
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号