📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1395
ClientLeft = 60
ClientTop = 345
ClientWidth = 6960
LinkTopic = "Form1"
ScaleHeight = 1395
ScaleWidth = 6960
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "打开记录集"
Height = 375
Left = 1080
TabIndex = 1
Top = 840
Width = 3735
End
Begin VB.CommandButton Command1
Caption = "连接Access数据库"
Height = 495
Left = 1080
TabIndex = 0
Top = 120
Width = 3735
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()
Dim con As Object
On Error GoTo ErrHandle
Set con = New ADODB.Connection
Dim strcon As String
strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\gongcheng.mdb;Persist Security Info=False;"
con.Open strcon
If con Is Nothing Then
MsgBox "连接失败,请你检查数据库路径!"
Else
MsgBox "连接成功!"
End If
Exit Sub
ErrHandle:
MsgBox "连接失败,请你检查数据库路径!"
End Sub
Private Sub ADOOpenRecordset()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim fld As ADODB.Field
'打开连接
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=.\gongcheng.mdb; "
'打开方式:向前、只读
rst.Open "SELECT * FROM 客户表 ", cnn, adOpenForwardOnly, adLockReadOnly
'输出第一个记录的所有字段值
For Each fld In rst.Fields
Debug.Print fld.Value & ";";
Next
Debug.Print
'关闭数据记录集对象
rst.Close
cnn.Close
End Sub
Private Sub Command2_Click()
Dim con As Object
On Error GoTo ErrHandle
Set con = New ADODB.Connection
Dim strcon As String
strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\gongcheng.mdb;Persist Security Info=False;"
con.Open strcon
If con Is Nothing Then
MsgBox "连接失败,请你检查数据库路径!"
Else
MsgBox "连接成功!"
End If
ADOOpenRecordset
ErrHandle:
MsgBox "连接失败,请你检查数据库路径!"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -