📄 addstu.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "添加学生"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command2
Caption = "取消"
Height = 375
Left = 2520
TabIndex = 7
Top = 2400
Width = 975
End
Begin VB.CommandButton Command1
Caption = "确定"
Height = 375
Left = 840
TabIndex = 6
Top = 2400
Width = 975
End
Begin VB.TextBox Text3
Height = 375
Left = 1560
TabIndex = 5
Top = 1680
Width = 1455
End
Begin VB.TextBox Text2
Height = 375
Left = 1560
TabIndex = 4
Top = 1080
Width = 1455
End
Begin VB.TextBox Text1
Height = 375
Left = 1560
TabIndex = 3
Top = 480
Width = 1455
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "班级"
Height = 180
Left = 840
TabIndex = 2
Top = 1680
Width = 360
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "学生学号"
Height = 180
Left = 480
TabIndex = 1
Top = 1080
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "学生姓名"
Height = 180
Left = 480
TabIndex = 0
Top = 480
Width = 720
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
Dim sql As String
If Trim(Text1.Text) = "" Then
MsgBox "学生姓名不能为空", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "学号不能为空", vbOKOnly + vbExclamation, ""
Text2.SetFocus
Exit Sub
End If
If Trim(Text3.Text) = "" Then
MsgBox "班级不能为空", vbOKOnly + vbExclamation, ""
Text3.SetFocus
Exit Sub
End If
sql = "select * from 学生管理"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
While (rs.EOF = False)
If Trim(rs.Fields(0)) = Trim(Text2.Text) Then
MsgBox "学号不能重复!", vbOKOnly + vbExclamation, ""
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Exit Sub
Else
rs.MoveNext
End If
Wend
rs.AddNew
rs.Fields(0) = Text2.Text
rs.Fields(1) = Text1.Text
rs.Fields(2) = Text3.Text
rs.Update
rs.Close
MsgBox "添加用户成功", vbOKOnly + vbExclamation, ""
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -