📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1935
ClientLeft = 60
ClientTop = 345
ClientWidth = 4710
LinkTopic = "Form1"
ScaleHeight = 1935
ScaleWidth = 4710
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "浏览记录"
Enabled = 0 'False
Height = 375
Left = 2520
TabIndex = 1
Top = 720
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "创建数据库"
Height = 375
Left = 720
TabIndex = 0
Top = 720
Width = 1215
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()
On Error GoTo DealError
Dim objCon As Connection, strCn As String, strSQL As String
Set objCon = New Connection '创建连接数据库服务器的Connection对象
'建立与数据库服务器的连接
strCn = "Provider=SQLOLEDB.1;User ID=sa;Data Source=(local)"
objCon.ConnectionString = strCn
objCon.Open
'执行SQL语句创建数据库
strSQL = "CREATE DATABASE 实例2库"
objCon.Execute strSQL
MsgBox "成功创建数据库"
objCon.Close
'重新建立数据库服务器连接,并连接到指定数据库
strCn = "Provider=SQLOLEDB.1;User ID=sa;" & _
"Data Source=(local);Initial Catalog=实例2库"
objCon.ConnectionString = strCn
objCon.Open
'执行SQL语句创建数据库表对象
strSQL = "CREATE TABLE 测试表( " & _
"用户名 varchar(13) not null primary key, " & _
"口令 char(6) not null )"
objCon.Execute strSQL
MsgBox "成功创建数据库表"
'为新建的“测试表”表添加三条记录
strSQL = "INSERT 测试表 (用户名,口令) " & _
"VALUES ('Administrator',123456)"
objCon.Execute strSQL
strSQL = "INSERT 测试表 (用户名,口令) " & _
"VALUES ('Admin',135789)"
objCon.Execute strSQL
strSQL = "INSERT 测试表 (用户名,口令) " & _
"VALUES ('叮当',123321)"
objCon.Execute strSQL
MsgBox "成功为表添加了三条记录"
'关闭数据库连接,释放Connection对象
objCon.Close
Set objCon = Nothing
'启用浏览记录按钮
Command2.Enabled = True
Exit Sub
DealError:
'显示出错信息
MsgBox "数据库创建过程出错:" & Err.Description
End Sub
Private Sub Command2_Click()
'显示记录浏览窗体
Form2.Show
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -