⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 VB连接SQL实例,对初学者很有帮助,帮助大大滴有
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "分页显示记录集的内容"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5460
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   5460
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "开始分页显示记录集"
      Height          =   615
      Left            =   1560
      TabIndex        =   0
      Top             =   960
      Width           =   2415
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Sub AbsolutePageX()
  '定义相关的ADO对象及参数
   Dim rstEmployees As ADODB.Recordset
   Dim strCnn As String
   Dim strMessage As String
   Dim intPage As Integer
   Dim intPageCount As Integer
   Dim intRecord As Integer
   '使用客户机游标为雇员表打开一个记录集
   strCnn = "Provider=sqloledb;" & _
              "Data Source=mynetserver; " & _
"Initial Catalog=pubs; " & _
"User Id=sa; " & _
"Password=12345678; "
    Set rstEmployees = New ADODB.Recordset
   '使用客户机游标激活 AbsolutePosition 属性
   rstEmployees.CursorLocation = adUseClient
   rstEmployees.Open "employee", strCnn, , , adCmdTable
   '显示姓名和受雇日期字段,每次6个记录。这里修改设置的值就可以使每页按照设定的值显示
   rstEmployees.PageSize = 6
   'intPageCount变量返回总共的分页数
   intPageCount = rstEmployees.PageCount
   '从第1页到最后1页,开始显示内容
   For intPage = 1 To intPageCount
      '记录集的定位属性AbsolutePage指向设置的页
rstEmployees.AbsolutePage = intPage
      strMessage = ""
      '显示每页的6个记录
      For intRecord = 1 To rstEmployees.PageSize
         strMessage = strMessage & _
            rstEmployees!fname & " " & _
            rstEmployees!lname & " " & _
            rstEmployees!hire_date & vbCr
         rstEmployees.MoveNext
         '如果已经到记录尾,则退出,否则继续显示
If rstEmployees.EOF Then Exit For
      Next intRecord
      '弹出对话框,显示记录的信息
MsgBox strMessage
   '显示下一页
Next intPage
   '关闭记录集
rstEmployees.Close
End Sub


Private Sub Command1_Click()
  Call AbsolutePageX
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -