📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtUserName
Height = 270
Left = 1560
Locked = -1 'True
TabIndex = 4
Top = 840
Width = 1695
End
Begin VB.TextBox txtPassword
Height = 270
Left = 1560
Locked = -1 'True
TabIndex = 3
Top = 1200
Width = 1695
End
Begin VB.CommandButton cmdPre
Caption = "前一记录"
Height = 375
Left = 960
TabIndex = 2
Top = 1680
Width = 975
End
Begin VB.CommandButton cmdNext
Caption = "后一记录"
Height = 375
Left = 2880
TabIndex = 1
Top = 1680
Width = 975
End
Begin VB.TextBox txtMsg
Height = 270
Left = 2160
Locked = -1 'True
TabIndex = 0
Top = 1680
Width = 495
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用户名"
Height = 180
Left = 840
TabIndex = 6
Top = 840
Width = 540
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "口 令"
Height = 180
Left = 840
TabIndex = 5
Top = 1200
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim objRS As Recordset '定义需要的窗体级Recordset对象
Private Sub cmdNext_Click()
'使后一记录成为当前记录
objRS.MoveNext
'如果记录指针指向最后一个记录之后,则使其指向最后记录
If objRS.EOF Then
objRS.MoveLast
End If
'显示当前记录数据
txtUserName = objRS.Fields("用户名").Value
txtPassword = objRS.Fields("口令").Value
txtMsg = objRS.AbsolutePosition & "/" & objRS.RecordCount
End Sub
Private Sub cmdPre_Click()
objRS.MovePrevious '使前一记录成为当前记录
'如果记录指针指向最后一个记录之后,则使其指向最后一个记录
If objRS.BOF Then
objRS.MoveFirst
End If
'显示当前记录数据
txtUserName = objRS.Fields("用户名").Value
txtPassword = objRS.Fields("口令").Value
txtMsg = objRS.AbsolutePosition & "/" & objRS.RecordCount
End Sub
Private Sub Form_Load()
Dim objCn As New Connection '定义一个Connection对象,并进行实例化
With objCn '建立数据库连接
.Provider = "SQLOLEDB"
'登录我自己建立的数据库
'用户名sa密码xuanxuan数据库名test
.ConnectionString = "User ID=sa;PWD=xuanxuan;Data Source=(local);" & _
"Initial Catalog=test"
.Open
End With
Set objRS = New Recordset '创建客户端的记录集
With objRS
.CursorLocation = adUseClient '指定使用客户端光标
.CursorType = adOpenStatic '指定使用静态光标
'访问数据库中的表
.Open "SELECT * FROM 测试表", objCn
Set .ActiveConnection = Nothing
End With
objCn.Close '释放数据库连接
Set objCn = Nothing
'显示第一个记录数据
txtUserName = objRS.Fields("用户名").Value
txtPassword = objRS.Fields("口令").Value
txtMsg = objRS.AbsolutePosition & "/" & objRS.RecordCount
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objRS = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -