📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "TestConnect"
ClientHeight = 2385
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2385
ScaleWidth = 4680
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command1
Caption = "关 闭"
Height = 495
Left = 1680
TabIndex = 0
Top = 1560
Width = 1335
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "此实例用来演示Connection对象的功能"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 120
TabIndex = 1
Top = 360
Width = 4410
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
'创建Connection对象cnn,关键New用于创建新对象
Dim cnn As New ADODB.Connection
If Dir(App.Path + "\人事.mdb") <> "" Then
'设置连接字符串ConnectionString属性
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
+ " Data Source=" + App.Path + "\人事.mdb; "
'打开到数据库的连接
cnn.Open
'判断连接的状态
If cnn.State = adStateOpen Then
'如果连接成功,则显示OK
MsgBox "打开数据库"
End If
'关闭连接
cnn.Close
'判断连接的状态
If cnn.State = adStateClosed Then
'如果连接成功,则显示OK
MsgBox "关闭数据库"
End If
Else
MsgBox ("找不到人事数据库")
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -