• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

数据在窗体中的翻页

发布: 2007-5-25 09:21 | 作者: no_com | 来源: 互联网 | 查看: 38次 | 进入软件测试论坛讨论

领测软件测试网

用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

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/