📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "ADO对象通过OLE DB连接Access"
ClientHeight = 1710
ClientLeft = 60
ClientTop = 450
ClientWidth = 4755
LinkTopic = "Form1"
ScaleHeight = 1710
ScaleWidth = 4755
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdConn
Caption = "连接数据库"
Height = 375
Left = 3360
TabIndex = 4
Top = 1200
Width = 1215
End
Begin VB.TextBox txtPassword
Height = 270
IMEMode = 3 'DISABLE
Left = 1320
PasswordChar = "*"
TabIndex = 3
Top = 720
Width = 2175
End
Begin VB.TextBox txtDBName
Height = 270
Left = 1320
TabIndex = 1
Top = 240
Width = 3255
End
Begin VB.Label Label3
Caption = "密码:"
Height = 255
Left = 240
TabIndex = 2
Top = 720
Width = 1095
End
Begin VB.Label Label1
Caption = "数据库:"
Height = 255
Left = 240
TabIndex = 0
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 ConnX As ADODB.Connection
Private Sub cmdConn_Click()
'生成连接字符串
If txtPassword.Text = "" Then
'数据库没有密码
ConnX.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & txtDBName.Text
Else
'数据库有密码
ConnX.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & txtDBName.Text & _
";Jet OLEDB:Database Password=" & txtPassword.Text
End If
On Error GoTo ConnErr
'连接数据库
ConnX.Open
MsgBox "连接数据库成功!", vbInformation, "连接"
Exit Sub
ConnErr:
MsgBox "连接数据库错误!", vbInformation, "连接"
End Sub
Private Sub Form_Load()
Set ConnX = New Connection
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set ConnX = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -