数据在窗体中的翻页

2008-04-10 03:07:16来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

用mshflexgrid控件实现数据库翻页
========================
打开vb6.0
在窗体中加入2个command控件,1个mshflexgrid控件
代码:
-----------------------------
Dim intpage As Integer

Private Sub Command1_Click()
intpage = intpage - 1
page intpage
End Sub

Private Sub Command2_Click()

intpage = intpage 1
page intpage
End Sub

Sub page(intpagecount As Integer)
On Error Resume Next
Dim cn As New ADODB.Connection
Dim cm As New ADODB.Command
Dim rs As New ADODB.Recordset
MSHFlexGrid1.Clear
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\Students.mdb"
cn.Open
cm.ActiveConnection = cn
rs.CursorLocation = adUseClient
rs.Open "select * from 新生入学信息表 ", cn, adOpenDynamic, adLockBatchOptimistic
rs.PageSize = 10
If intpagecount > rs.PageCount Then
intpagecount = rs.PageCount
End If
If intpagecount < 1 Then
intpagecount = 1
End If
rs.AbsolutePage = intpagecount

''''MsgBox rs.Fields.Count
With MSHFlexGrid1
.Cols = rs.Fields.Count
.Rows = 10
For i = 0 To 9
For j = 0 To rs.Fields.Count - 1
.TextMatrix(i, j) = rs.Fields(j)
Next
rs.MoveNext
Next
End With
End Sub

Private Sub Form_Load()
Command2.Caption = "下一页"
Command1.Caption = "上一页"
page 1
End Sub

作者主页:http://risk.y365.com

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:神奇的*号

下一篇:让窗体的标题栏不相应鼠标双击