Option Explicit
Dim db As New ADODB.Connection
Dim lCurrentPage As LongPrivate Sub cmdNext_Click()
lCurrentPage = lCurrentPage + 1
Call LoadListBox(lCurrentPage)
End SubPrivate Sub cmdPrevious_Click()
If lCurrentPage > 1 Then
lCurrentPage = lCurrentPage - 1
Call LoadListBox(lCurrentPage)
End If
End SubPrivate Sub Form_Load()
Dim strConnection As String
strConnection = "DRIVER={SQL Server};SERVER=192.1.1.1;uid=sa;Database=mydb;pwd=;"
db.Open strConnection
lCurrentPage = 1
Call LoadListBox(lCurrentPage)End Sub
Private Sub LoadListBox(lPage As Long)
Dim adoPrimaryRS As New ADODB.RecordsetDim lPageCount As Long
Dim nPageSize As Integer
Dim lCount As LongnPageSize = 7
adoPrimaryRS.Open "SELECT * FROM mytable", db, adOpenStatic, adLockOptimisticadoPrimaryRS.PageSize = nPageSize
lPageCount = adoPrimaryRS.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End IftxtPage.Text = lPageadoPrimaryRS.AbsolutePage = lCurrentPageWith lbxRecords
.Clear
lCount = 0
Do While Not adoPrimaryRS.EOF
.AddItem adoPrimaryRS("Id")
lCount = lCount + 1
If lCount = nPageSize Then
Exit Do
End If
adoPrimaryRS.MoveNext
LoopEnd With
End SubPrivate Sub Form_Unload(Cancel As Integer)
If Not db Is Nothing Then
db.Close
End If
Set db = Nothing
End Sub
Dim db As New ADODB.Connection
Dim lCurrentPage As LongPrivate Sub cmdNext_Click()
lCurrentPage = lCurrentPage + 1
Call LoadListBox(lCurrentPage)
End SubPrivate Sub cmdPrevious_Click()
If lCurrentPage > 1 Then
lCurrentPage = lCurrentPage - 1
Call LoadListBox(lCurrentPage)
End If
End SubPrivate Sub Form_Load()
Dim strConnection As String
strConnection = "DRIVER={SQL Server};SERVER=192.1.1.1;uid=sa;Database=mydb;pwd=;"
db.Open strConnection
lCurrentPage = 1
Call LoadListBox(lCurrentPage)End Sub
Private Sub LoadListBox(lPage As Long)
Dim adoPrimaryRS As New ADODB.RecordsetDim lPageCount As Long
Dim nPageSize As Integer
Dim lCount As LongnPageSize = 7
adoPrimaryRS.Open "SELECT * FROM mytable", db, adOpenStatic, adLockOptimisticadoPrimaryRS.PageSize = nPageSize
lPageCount = adoPrimaryRS.PageCount
If lCurrentPage > lPageCount Then
lCurrentPage = lPageCount
End IftxtPage.Text = lPageadoPrimaryRS.AbsolutePage = lCurrentPageWith lbxRecords
.Clear
lCount = 0
Do While Not adoPrimaryRS.EOF
.AddItem adoPrimaryRS("Id")
lCount = lCount + 1
If lCount = nPageSize Then
Exit Do
End If
adoPrimaryRS.MoveNext
LoopEnd With
End SubPrivate Sub Form_Unload(Cancel As Integer)
If Not db Is Nothing Then
db.Close
End If
Set db = Nothing
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货