frmstudent.frm
来自「数据库课程设计」· FRM 代码 · 共 285 行
FRM
285 行
VERSION 5.00
Begin VB.Form frmStudent
Caption = "添加学生"
ClientHeight = 3765
ClientLeft = 60
ClientTop = 345
ClientWidth = 6300
LinkTopic = "Form1"
ScaleHeight = 3765
ScaleWidth = 6300
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3240
TabIndex = 18
Top = 3240
Width = 1335
End
Begin VB.CommandButton cmdOk
Caption = "添加(&A)"
Height = 375
Left = 1560
TabIndex = 17
Top = 3240
Width = 1335
End
Begin VB.Frame Frame1
Caption = "学生基本信息"
Height = 2895
Left = 120
TabIndex = 0
Top = 120
Width = 5895
Begin VB.TextBox txtMemo
Height = 855
Left = 960
TabIndex = 16
Text = "Text6"
Top = 1800
Width = 4575
End
Begin VB.TextBox txtAddress
Height = 285
Left = 960
TabIndex = 14
Text = "Text5"
Top = 1440
Width = 4575
End
Begin VB.TextBox txtTel
Height = 285
Left = 3720
TabIndex = 12
Text = "Text4"
Top = 1080
Width = 1815
End
Begin VB.ComboBox cboSex
Height = 315
Left = 960
TabIndex = 10
Text = "Combo2"
Top = 1080
Width = 1815
End
Begin VB.TextBox txtBirth
Height = 285
Left = 960
TabIndex = 8
Text = "Text2"
Top = 720
Width = 1815
End
Begin VB.ComboBox cboClass
Height = 315
Left = 3720
TabIndex = 6
Text = "Combo1"
Top = 720
Width = 1815
End
Begin VB.TextBox txtName
Height = 285
Left = 960
TabIndex = 5
Text = "Text3"
Top = 360
Width = 1455
End
Begin VB.TextBox txtNo
Height = 285
Left = 3720
TabIndex = 2
Text = "Text1"
Top = 360
Width = 1815
End
Begin VB.Label Label8
Caption = "备注:"
Height = 255
Left = 360
TabIndex = 15
Top = 1800
Width = 855
End
Begin VB.Label Label7
Caption = "地址:"
Height = 255
Left = 360
TabIndex = 13
Top = 1440
Width = 1095
End
Begin VB.Label Label6
Caption = "电话:"
Height = 255
Left = 3120
TabIndex = 11
Top = 1080
Width = 615
End
Begin VB.Label Label5
Caption = "性别:"
Height = 255
Left = 360
TabIndex = 9
Top = 1080
Width = 615
End
Begin VB.Label Label4
Caption = "生日:"
Height = 255
Left = 360
TabIndex = 7
Top = 720
Width = 615
End
Begin VB.Label Label3
Caption = "姓名:"
Height = 255
Left = 360
TabIndex = 4
Top = 360
Width = 615
End
Begin VB.Label Label2
Caption = "班级:"
Height = 255
Left = 3120
TabIndex = 3
Top = 720
Width = 615
End
Begin VB.Label Label1
Caption = "学号:"
Height = 255
Left = 3120
TabIndex = 1
Top = 360
Width = 615
End
End
End
Attribute VB_Name = "frmStudent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim rstStudent As ADODB.Recordset
Dim stuNo As String
Dim stuName As String
Dim birthdate As String
Dim sex As String
Dim stuClass As String
Dim tel As String
Dim address As String
Dim memo As String
'获取数据
stuNo = Trim(txtNo.Text)
stuName = Trim(txtName.Text)
birthdate = Trim(txtBirth.Text)
sex = cboSex.Text
stuClass = cboClass.Text
tel = Trim(txtTel.Text)
address = Trim(txtAddress.Text)
memo = Trim(txtMemo.Text)
If stuNo = "" Or stuName = "" Then
MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'添加新记录
sqlStr = "select * from studentInfo"
Set rstStudent = ExecuteSQL(sqlStr, msgText)
rstStudent.AddNew
rstStudent.Fields("stu_no") = stuNo
rstStudent.Fields("name") = stuName
rstStudent.Fields("class_no") = stuClass
rstStudent.Fields("birthdate") = birthdate
rstStudent.Fields("sex") = sex
rstStudent.Fields("address") = address
rstStudent.Fields("telno") = tel
rstStudent.Fields("memo") = memo
rstStudent.Update
rstStudent.Close
MsgBox "学生信息添加完成!", vbOKOnly + vbExclamation, "警告"
initForm
initClass
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initForm
initClass
End Sub
Sub initForm()
'初始化输入框
txtName = ""
txtBirth = ""
txtNo = ""
txtTel = ""
txtAddress = ""
txtMemo = ""
cboSex.Clear
cboSex.AddItem "男"
cboSex.AddItem "女"
cboSex.ListIndex = 0
End Sub
Sub initClass()
Dim rstClass As ADODB.Recordset
'从数据库中读取所有班级并添加到组合列表框中
'方便录入时进行选择
sqlStr = "select className from classInfo"
Set rstClass = ExecuteSQL(sqlStr, msgText)
cboClass.Clear
If Not rstClass.EOF Then
Do While Not rstClass.EOF
cboClass.AddItem Trim(rstClass.Fields(0))
rstClass.MoveNext
Loop
cboClass.ListIndex = 0
Else
MsgBox "请添加客房类型!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstClass.Close
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?