数据在窗体中的翻页

用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

阅读更多
个人分类: visual basic
想对作者说点什么? 我来说一句

MSSQL百完数据翻页

2008年10月28日 845B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭