作者:王勋
当数据量太大时,最好的办法是分页处理数据库中的数据
''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