📄 addstu.frm
字号:
VERSION 5.00
Object = "{CE671F01-259E-40DA-92FE-95803E2ECBB5}#1.0#0"; "SmartXPButton.ocx"
Object = "{C932BA88-4374-101B-A56C-00AA003668DC}#1.1#0"; "MSMASK32.OCX"
Begin VB.Form addstu
BackColor = &H00E7DFE7&
Caption = "学生注册"
ClientHeight = 4740
ClientLeft = 60
ClientTop = 450
ClientWidth = 6945
Icon = "addstu.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 4740
ScaleWidth = 6945
StartUpPosition = 2 '屏幕中心
Begin VB.ComboBox Combo3
Height = 300
Left = 5160
Style = 2 'Dropdown List
TabIndex = 5
Top = 2640
Width = 1455
End
Begin VB.ComboBox Combo2
Height = 300
Left = 2760
Style = 2 'Dropdown List
TabIndex = 4
Top = 2640
Width = 1575
End
Begin VB.ComboBox Combo1
Height = 300
Left = 2760
Style = 2 'Dropdown List
TabIndex = 2
Top = 1920
Width = 1575
End
Begin VB.TextBox Text5
Height = 390
Left = 5160
TabIndex = 1
Top = 1200
Width = 1455
End
Begin VB.TextBox Text4
Height = 375
Left = 2760
TabIndex = 6
Top = 3240
Width = 1575
End
Begin VB.TextBox Text1
Height = 375
Left = 2760
TabIndex = 0
Top = 1200
Width = 1575
End
Begin SmartXPButton.XpButton cmdcancel
Height = 495
Left = 3840
TabIndex = 8
Top = 3840
Width = 1815
_ExtentX = 3201
_ExtentY = 873
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "取消(&C)"
PictureSmoothBackColor= 15460844
ButtonPicture = "addstu.frx":0A02
End
Begin SmartXPButton.XpButton cmdok
Height = 495
Left = 1080
TabIndex = 7
Top = 3840
Width = 1695
_ExtentX = 2990
_ExtentY = 873
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "添加(&O)"
PictureSmoothBackColor= 15460844
ButtonPicture = "addstu.frx":1414
End
Begin MSMask.MaskEdBox txtBirth
Height = 390
Left = 5160
TabIndex = 3
Top = 1920
Width = 1455
_ExtentX = 2566
_ExtentY = 688
_Version = 393216
MaxLength = 10
Mask = "####-##-##"
PromptChar = "_"
End
Begin VB.Label Label8
BackStyle = 0 'Transparent
Caption = "籍贯:"
Height = 255
Left = 2160
TabIndex = 16
Top = 3360
Width = 495
End
Begin VB.Label Label7
BackStyle = 0 'Transparent
Caption = "系编号:"
Height = 255
Left = 4440
TabIndex = 15
Top = 2760
Width = 1215
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Caption = "生日:"
Height = 495
Left = 4560
TabIndex = 14
Top = 2040
Width = 1215
End
Begin VB.Label Label5
BackStyle = 0 'Transparent
Caption = "姓名:"
Height = 375
Left = 4560
TabIndex = 13
Top = 1320
Width = 1215
End
Begin VB.Image Image1
Height = 1740
Left = 240
Picture = "addstu.frx":1E26
Top = 1200
Width = 1380
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "班级编号:"
Height = 375
Left = 1845
TabIndex = 12
Top = 2760
Width = 975
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "性别:"
Height = 255
Left = 2160
TabIndex = 11
Top = 2040
Width = 735
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "学号:"
Height = 495
Left = 2160
TabIndex = 10
Top = 1320
Width = 615
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "学生信息设置"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000002&
Height = 495
Left = 2520
TabIndex = 9
Top = 240
Width = 1935
End
End
Attribute VB_Name = "addstu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim myconn As New ADODB.Connection
Dim str As String
Dim MyStr As String
Dim myrs1 As New ADODB.Recordset
Dim myrs2 As New ADODB.Recordset
Dim MyRs As New ADODB.Recordset
Private Sub cmdcancel_Click()
myconn.Close
Unload Me
End Sub
Private Sub cmdok_Click()
On Error GoTo DbnotOpen
Set MyRs = New ADODB.Recordset
With MyRs
.Source = "student"
.ActiveConnection = myconn
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open , , , , adCmdTable
End With
If Val(txtBirth.Text) <> 0 Then
If Not IsDate(txtBirth.Text) Then
MsgBox "生日不是有效日期,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
txtBirth.Text = "____-__-__"
Exit Sub
End If
End If
If Len(Trim(Text1.Text)) <> 0 And Len(Trim(Combo1.Text)) <> 0 And Len(Trim(Combo2.Text)) <> 0 And Len(Trim(Text4.Text)) <> 0 And Len(Trim(Text5.Text)) <> 0 And Len(Trim(txtBirth.Text)) <> 0 And Len(Trim(Combo3.Text)) <> 0 Then
With MyRs
.AddNew
.Fields("BIRTHDAY") = Format(Trim(txtBirth.Text), "yyyy-mm-dd")
.Fields("ID") = Trim(Text1.Text)
.Fields("NAME") = Trim(Text5.Text)
.Fields("SEX") = Trim(Combo1.Text)
.Fields("CLASS") = Trim(Combo2.Text)
.Fields("DEPARTMENT") = Trim(Combo3.Text)
.Fields("NATIVE_PLACE") = Trim(Text4.Text)
.Update
End With
MsgBox "学生注册信息已添加成功!", vbOKOnly + vbInformation, "提示信息"
Text1.Text = ""
Combo1.Clear
Combo2.Clear
Text4.Text = ""
Text5.Text = ""
txtBirth.Text = "____-__-__"
Combo3.Clear
Combo1.AddItem "男"
Combo1.AddItem "女"
str = "select ID from DEPARTMENT"
Set myrs1 = myconn.Execute(str)
While Not myrs1.EOF
Combo3.AddItem myrs1!ID
myrs1.MoveNext
Wend
str = "select ID from CLASS"
Set myrs2 = myconn.Execute(str)
While Not myrs2.EOF
Combo2.AddItem myrs2!ID
myrs2.MoveNext
Wend
txtBirth.Text = "____-__-__"
Text1.SetFocus
Else
MsgBox "学生注册信息没有填写完整!", vbOKOnly + vbExclamation, "错误提示"
End If
DbnotOpen:
If Err = -2147217873 Then
MsgBox "数据库中存在重复的记录!" & vbCrLf & vbCrLf & "学生注册失败!", vbOKOnly + vbExclamation, "错误提示"
Unload Me
Load addstu
addstu.Show
End If
If Err = -2147352571 Then
MsgBox "生日不是有效日期,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
txtBirth.Text = "____-__-__"
Exit Sub
End If
If Err = -2147217887 Then
MsgBox " 输入的学号长度或姓名或者籍贯越界,请重新输入!", vbInformation, "提示信息"
Text1.SetFocus
Text1.Text = ""
Text4.Text = ""
Text5.Text = ""
Exit Sub
End If
End Sub
Private Sub Form_Load()
Set myconn = New ADODB.Connection
myconn.ConnectionString = "driver={SQL Server};" & _
"server=(local);uid=sa;pwd=;database=student_info"
myconn.Open
'***** 使用Recordset对象的Open方法创建记录集 *****
'MyRs.Open "manager", MyConn, adOpenStatic, adLockOptimistic, adCmdTable
Combo1.AddItem "男"
Combo1.AddItem "女"
str = "select ID from DEPARTMENT"
Set myrs1 = myconn.Execute(str)
While Not myrs1.EOF
Combo3.AddItem myrs1!ID
myrs1.MoveNext
Wend
str = "select ID from CLASS"
Set myrs2 = myconn.Execute(str)
While Not myrs2.EOF
Combo2.AddItem myrs2!ID
myrs2.MoveNext
Wend
txtBirth.Text = "____-__-__"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -