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

📄 form1.frm

📁 vb数据库编程资料
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1980
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5265
   LinkTopic       =   "Form1"
   ScaleHeight     =   1980
   ScaleWidth      =   5265
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   3240
      TabIndex        =   3
      Text            =   "Text3"
      Top             =   1440
      Width           =   1695
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   3240
      TabIndex        =   2
      Text            =   "Text2"
      Top             =   840
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   3240
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   120
      Width           =   1935
   End
   Begin VB.ListBox List1 
      Height          =   1680
      Left            =   360
      TabIndex        =   0
      Top             =   120
      Width           =   1455
   End
   Begin VB.Label Label3 
      Caption         =   "字段值:"
      Height          =   495
      Left            =   2160
      TabIndex        =   6
      Top             =   1440
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "字段类型:"
      Height          =   375
      Left            =   2160
      TabIndex        =   5
      Top             =   840
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "字段长度:"
      Height          =   375
      Left            =   2160
      TabIndex        =   4
      Top             =   240
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Conn As New ADODB.Connection  '连接变量
Dim SqlString As String            '查询字符串
Dim Connstring As String           '连接字符串
Dim RS1 As New ADODB.Recordset     '记录集变量
Dim Cmd As New ADODB.Command      'Command对象
Private Sub Form_Load()
  Connstring = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & App.Path & "\教学.mdb"
  '设置连接字符串
  With Conn
     .ConnectionString = Connstring '给ConnectionString属性赋值
     .ConnectionTimeout = 10
     .Open '给连接的ConnectionString属性赋值,然后使用求带参数的Open方法打开连接
  End With
  MsgBox ("连接成功")
   Set Cmd.ActiveConnection = Conn   '设置Command对象的ActiveConnection为某个打开的连接
 SqlString = "教师表" '形成查询字符串1
 Cmd.CommandText = SqlString     '设置Command对象执行的命令字符串
 Cmd.CommandType = adCmdTable    '设置命令类型
 Set RS1 = Cmd.Execute           '执行命令得到一个结果记录集
 List1.Clear
 For I = 0 To RS1.Fields.Count - 1  '本循环把RS1记录集中的所有字段的字段添加到列表框中
     List1.AddItem RS1.Fields(I).Name
 Next I

End Sub

Private Sub List1_Click()
  Text1.Text = RS1.Fields(List1.ListIndex).DefinedSize   ' 显示选定字段的DefineSize属性
  Text2.Text = RS1.Fields(List1.ListIndex).Type          '显示选定字段的Type属性
  Text3.Text = RS1.Fields(List1.ListIndex).Value         '选定选定字段的Value属性
End Sub

⌨️ 快捷键说明

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