📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "TestRecordset"
ClientHeight = 2265
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2265
ScaleWidth = 4680
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command1
Caption = "关 闭"
Height = 495
Left = 1673
TabIndex = 0
Top = 1560
Width = 1335
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "此实例用来演示Recordset对象的功能"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Left = 203
TabIndex = 1
Top = 360
Width = 4275
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
'创建Recordset对象rs1
Dim rs1 As New ADODB.Recordset
'设置查询记录集的SQL语句,从表Departments中读取记录
Dim varSource As String
varSource = "SELECT * FROM Departments"
If Dir(App.Path + "\人事.mdb") <> "" Then
'设置连接字符串ConnectionString属性
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
+ " Data Source=" + App.Path + "\人事.mdb; "
'打开到数据库的连接
cnn.Open
'设置rs1的ActiveConnection属性,指定与其关联的数据库连接
Set rs1.ActiveConnection = cnn
'设置游标类型
rs1.CursorType = adOpenStatic
'打开记录集,将从表Departments中读取的结果集保存到记录集rs1中
rs1.Open varSource
'显示记录集中记录的数量
MsgBox "当前记录集中共有记录 " + Trim(rs1.RecordCount) + " 个"
'将指针移动到记录集的最后
rs1.Move rs1.RecordCount
'判断EOF属性的值
If rs1.EOF = True Then
MsgBox "已经达到记录集的结尾"
End If
'关闭记录集
rs1.Close
'关闭cnn对象
cnn.Close
Else
MsgBox ("找不到人事数据库")
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -