📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "数据库登陆"
ClientHeight = 4635
ClientLeft = 3615
ClientTop = 3330
ClientWidth = 8760
LinkTopic = "Form1"
ScaleHeight = 4635
ScaleWidth = 8760
Begin VB.CommandButton Enter
Caption = "进入"
Enabled = 0 'False
Height = 495
Left = 6000
TabIndex = 9
Top = 2280
Width = 1815
End
Begin VB.CommandButton Connect
BackColor = &H80000002&
Caption = "连接数据库"
Height = 495
Left = 6000
TabIndex = 8
Top = 1080
Width = 1815
End
Begin VB.Frame Forms_attach
BackColor = &H8000000E&
Caption = "登陆数据库"
ForeColor = &H80000002&
Height = 3375
Left = 480
TabIndex = 0
Top = 600
Width = 7935
Begin VB.TextBox Password
Height = 375
IMEMode = 3 'DISABLE
Left = 1080
PasswordChar = "*"
TabIndex = 7
Text = "sa"
Top = 1920
Width = 2175
End
Begin VB.TextBox User
Height = 375
Left = 1080
TabIndex = 6
Text = "sa"
Top = 1200
Width = 2175
End
Begin VB.TextBox Server
Height = 285
Left = 1080
TabIndex = 5
Text = "OEM-MICRO"
Top = 480
Width = 2175
End
Begin VB.Frame Frame1
Caption = "Frame1"
Height = 135
Left = 360
TabIndex = 3
Top = 2040
Width = 15
End
Begin VB.Label Label_password
BackColor = &H80000009&
Caption = "密码"
Height = 495
Left = 240
TabIndex = 4
Top = 1920
Width = 735
End
Begin VB.Label Label_user
BackColor = &H80000009&
Caption = "用户"
Height = 615
Left = 240
TabIndex = 2
Top = 1200
Width = 855
End
Begin VB.Label Label_sever
BackColor = &H80000009&
Caption = "服务器"
Height = 495
Left = 240
TabIndex = 1
Top = 480
Width = 975
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public AdminID As String
Public Admin_type As String
Public cnTest As ADODB.Connection
Public cnCmd As ADODB.Command
Public cnRecord As ADODB.Recordset
Public Borrow_money As Integer
Public Max_days As Integer
'--------------------连接数据库常用的三个ADO对象---------------------------
Public Stropen As String
Private Sub Connect_Click()
On Error GoTo ErrorHandle:
Stropen = "Provider = SQLOLEDB;"
Stropen = Stropen + "Data Source = " + Server.Text + ";"
Stropen = Stropen + "Initial Catalog = " + "project" + ";"
Stropen = Stropen + "User ID = " + User.Text + ";"
Stropen = Stropen + "Password = " + "'" + Password.Text + "'"
''--------------------------------------连接数据库------------------------
cnTest.Open (Stropen) '打开数据库连接,判断连接是否成功,失败后转跳到ErrorHandle:
MsgBox "Connect Successful!", 0 + vbInformation, "连接"
Enter.Enabled = True
Server.Enabled = False
User.Enabled = False
Password.Enabled = False
Connect.Enabled = False
Exit Sub ''这句的作用是如果连接成功后结束这个Sub
ErrorHandle:
Select Case (Err.Number)
Case 32755:
Case -2147217900:
MsgBox "属性类型定义错误", vbExclamation, "Error"
Case -2147217843:
MsgBox "无法连接指定的数据库服务器", vbExclamation, "Error"
Case Else:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation, "Error"
End Select
On Error GoTo 0
Exit Sub
End Sub
Private Sub Enter_Click()
Unload Form1
用户登陆.Show
''切换到功能窗口
End Sub
Private Sub Form_Load()
Set cnTest = New ADODB.Connection
Set cnCmd = New ADODB.Command
Set cnRecord = New ADODB.Recordset
''窗体Load时New出ADO对象
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -