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

📄 form1.frm

📁 vb数据库编程资料
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1695
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3720
   LinkTopic       =   "Form1"
   ScaleHeight     =   1695
   ScaleWidth      =   3720
   StartUpPosition =   3  '窗口缺省
   Begin VB.ListBox List2 
      Height          =   1320
      Left            =   2040
      TabIndex        =   3
      Top             =   240
      Width           =   1455
   End
   Begin VB.ListBox List1 
      Height          =   1320
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   1335
   End
   Begin VB.Label Label2 
      Caption         =   "课程名称:"
      Height          =   255
      Left            =   2040
      TabIndex        =   2
      Top             =   0
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "学生姓名:"
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   0
      Width           =   1695
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
  Dim Mydb As Database '定义数据库变量
  Dim Mywk As Workspace  '定义工作区变量
  Dim MyRec As Recordset  '定义记录集变量
  Set Mywk = CreateWorkspace("", "admin", "", dbUseJet) '创建Microsoft Jet工作区
  Set Mydb = Mywk.OpenDatabase(VB.App.Path & "\教务管理", False, True)
      '打开数据库
  Set MyRec = Mydb.OpenRecordset("学生", dbOpenTable)
         '通过Database变量的OpenRecordset方法创建记录集
  While Not MyRec.EOF   '该循环的作用是把学生姓名添加到List1列表框中
     List1.AddItem MyRec.Fields("姓名").Value   '把当前记录的学生姓名的值添加到List1中
     MyRec.MoveNext  '记录指针移到下一条
  Wend
  MyRec.Close  '关闭记录集
  Set MyRec = Mydb.TableDefs("课程").OpenRecordset(dbOpenTable)
         '通过TableDef变量的OpenRecordset方法创建记录集
  While Not MyRec.EOF '该循环的作用是把课名添加到List1列表框中
     List2.AddItem MyRec.Fields("课名").Value '把当前记录的课名的值添加到List1中
     MyRec.MoveNext '记录指针移到下一条
  Wend
  MyRec.Close '关闭记录集
End Sub

⌨️ 快捷键说明

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