📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "ADODB中使用OLEDB接口"
ClientHeight = 2835
ClientLeft = 60
ClientTop = 450
ClientWidth = 4350
LinkTopic = "Form1"
ScaleHeight = 2835
ScaleWidth = 4350
StartUpPosition = 2 '屏幕中心
Begin VB.ComboBox ComboName
Height = 300
Left = 600
TabIndex = 2
Text = "Combo1"
Top = 720
Width = 3255
End
Begin VB.CommandButton CmdExit
Caption = "退出"
Height = 375
Left = 2520
TabIndex = 1
Top = 2160
Width = 1335
End
Begin VB.CommandButton CmdExecute
Caption = "执行"
Height = 375
Left = 480
TabIndex = 0
Top = 2160
Width = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'声明段定义ADODB对象
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim connstr As String
'窗体启动时执行代码
Private Sub Form_Load()
ComboName.Text = "学生姓名列表"
End Sub
'单击执行按钮时的执行代码
Private Sub CmdExecute_Click()
'定义Connstr字符串的内容,体现不同的接口
'使用OLEDB接口的连接字符串内容,使用时请按照自己的环境设置账户和密码
connstr = " Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Password=12345678;Initial Catalog=db_student;Data Source = MYNETSERVER"
conn.ConnectionString = connstr
conn.Open connstr
rs.CursorLocation = adUseClient
rs.Open "T_STUDENT", conn, adOpenKeyset, adLockPessimistic
Do While Not rs.EOF And Not rs.BOF
ComboName.AddItem (rs.Fields(1))
rs.MoveNext
Loop
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
'单击退出按钮时的执行代码
Private Sub CmdExit_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -