?? frmdel_student.frm
字號:
VERSION 5.00
Begin VB.Form Frmdel_student
Caption = "刪改學生信息"
ClientHeight = 5925
ClientLeft = 60
ClientTop = 420
ClientWidth = 8025
LinkTopic = "Form1"
ScaleHeight = 5925
ScaleWidth = 8025
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame1
Caption = "選擇"
Height = 855
Left = 360
TabIndex = 4
Top = 240
Width = 7455
Begin VB.CommandButton cmd_query
Caption = "查詢"
Height = 375
Left = 6120
TabIndex = 25
Top = 360
Width = 975
End
Begin VB.ComboBox Stu_no1
Height = 300
Left = 3840
TabIndex = 8
Top = 360
Width = 1815
End
Begin VB.ComboBox Stu_class1
Height = 300
Left = 1320
TabIndex = 6
Top = 360
Width = 1455
End
Begin VB.Label Label2
Caption = "學號:"
Height = 255
Left = 3240
TabIndex = 7
Top = 360
Width = 615
End
Begin VB.Label Label1
Caption = "所屬班級:"
Height = 255
Left = 360
TabIndex = 5
Top = 360
Width = 975
End
End
Begin VB.Frame Frame2
Caption = "學生基本信息"
Height = 3495
Left = 360
TabIndex = 3
Top = 2160
Width = 7335
Begin VB.ComboBox Stu_class2
Height = 300
Left = 5160
TabIndex = 24
Top = 840
Width = 1695
End
Begin VB.ComboBox Stu_sex
Height = 300
Left = 1320
TabIndex = 23
Top = 1440
Width = 975
End
Begin VB.TextBox Stu_tel
Height = 270
Left = 5160
TabIndex = 22
Top = 1320
Width = 1695
End
Begin VB.TextBox Stu_no2
Height = 270
Left = 5160
TabIndex = 21
Top = 360
Width = 1335
End
Begin VB.TextBox Stu_memo
Height = 735
Left = 1320
TabIndex = 20
Top = 2400
Width = 5055
End
Begin VB.TextBox Stu_address
Height = 270
Left = 1320
TabIndex = 19
Top = 1920
Width = 5055
End
Begin VB.TextBox Stu_birth
Height = 270
Left = 1320
TabIndex = 18
Top = 960
Width = 1095
End
Begin VB.TextBox Stu_name
Height = 270
Left = 1320
TabIndex = 17
Top = 480
Width = 1095
End
Begin VB.Label Label10
Caption = "備注:"
Height = 255
Left = 360
TabIndex = 16
Top = 2280
Width = 615
End
Begin VB.Label Label9
Caption = "電話:"
Height = 255
Left = 4200
TabIndex = 15
Top = 1320
Width = 735
End
Begin VB.Label Label8
Caption = "班級:"
Height = 255
Left = 4200
TabIndex = 14
Top = 840
Width = 615
End
Begin VB.Label Label7
Caption = "學號:"
Height = 255
Left = 4200
TabIndex = 13
Top = 360
Width = 615
End
Begin VB.Label Label6
Caption = "地址:"
Height = 255
Left = 360
TabIndex = 12
Top = 1920
Width = 615
End
Begin VB.Label Label5
Caption = "性別:"
Height = 255
Left = 360
TabIndex = 11
Top = 1440
Width = 615
End
Begin VB.Label Label4
Caption = "生日:"
Height = 255
Left = 360
TabIndex = 10
Top = 960
Width = 615
End
Begin VB.Label Label3
Caption = "姓名:"
Height = 255
Left = 360
TabIndex = 9
Top = 480
Width = 615
End
End
Begin VB.CommandButton cmd_cancel
Caption = "返回"
Height = 495
Left = 5040
TabIndex = 2
Top = 1440
Width = 1095
End
Begin VB.CommandButton cmd_modify
Caption = "修改"
Height = 495
Left = 3000
TabIndex = 1
Top = 1440
Width = 1095
End
Begin VB.CommandButton cmd_delete
Caption = "刪除"
Height = 495
Left = 1200
TabIndex = 0
Top = 1440
Width = 975
End
End
Attribute VB_Name = "Frmdel_student"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_cancel_Click()
Unload Me
End Sub
Sub initStudentNo()
Dim rstNo As ADODB.Recordset
sqlStr = "select stu_no from students where class_no='" & Stu_class1.Text & "'"
Set rstNo = executesql(sqlStr, msgText)
Stu_no1.Clear
If Not rstNo.EOF Then
Do While Not rstNo.EOF
Stu_no1.AddItem Trim(rstNo.Fields(0))
rstNo.MoveNext
Loop
Stu_no1.ListIndex = 0
Else
MsgBox "沒有找到符合條件的數據1!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstNo.Close
End Sub
Sub getStudentInfo()
Dim rststudent As ADODB.Recordset
sqlStr = "select * from students where stu_no='" & Stu_no1.Text & "'"
Set rststudent = executesql(sqlStr, msgText)
If Not rststudent.EOF Then
Stu_no2 = Trim(rststudent.Fields("stu_no"))
Stu_name = Trim(rststudent.Fields("name"))
Stu_birth = Trim(rststudent.Fields("birthdate"))
Stu_class2.Text = Trim(rststudent.Fields("class_no"))
Stu_sex.Text = Trim(rststudent.Fields("sex"))
Stu_tel.Text = Trim(rststudent.Fields("telno"))
Stu_address.Text = Trim(rststudent.Fields("address"))
Stu_memo.Text = Trim(rststudent.Fields("memo"))
Else
MsgBox "沒找到符合條件的數據2!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rststudent.Close
End Sub
Private Sub cmd_delete_Click()
Dim conn As ADODB.Connection
sqlStr = "delete from students where stu_no='" & Stu_no1.Text & "'"
On Error GoTo exitsub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "成功刪除數據!"
exitsub:
conn.Close
initClass
End Sub
Private Sub cmd_modify_Click()
Dim rststudent As ADODB.Recordset
sqlStr = "update students set [name]='" & Stu_name.Text & "',[stu_no]='" & Stu_no2.Text & "',[Sex]='" & Stu_sex.Text & "',[birthdate]=#" & Stu_birth.Text & "#,[class_no]='" & Stu_class2.Text & "' ,[telno]='" & Stu_tel.Text & "',[address]='" & Stu_address.Text & "',[memo]='" & Stu_memo.Text & "' where stu_no='" & Stu_no1.Text & "'"
'Set rststudent = executesql(sqlStr, msgText)
On Error GoTo exitsub
Set conn = New ADODB.Connection
conn.Open connStr
conn.Execute sqlStr
MsgBox "修改數據成功!"
exitsub:
conn.Close
initClass
initform
End Sub
Sub initClass()
Dim rstclass As ADODB.Recordset
sqlStr = "select className from Classes"
Set rstclass = executesql(sqlStr, msgText)
Stu_class1.Clear
Stu_class2.Clear
If Not rstclass.EOF Then
Do While Not rstclass.EOF
Stu_class1.AddItem Trim(rstclass.Fields(0))
Stu_class2.AddItem Trim(rstclass.Fields(0))
rstclass.MoveNext
Loop
Stu_class1.ListIndex = 0
Stu_class2.ListIndex = 0
Else
MsgBox "請添加班級", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstclass.Close
End Sub
Private Sub cmd_query_Click()
getStudentInfo
End Sub
Private Sub Form_Load()
initClass
initform
Stu_sex.AddItem "男"
Stu_sex.AddItem "女"
End Sub
Sub initform()
Stu_class1 = ""
Stu_no1 = ""
Stu_no2 = ""
Stu_name = ""
Stu_class2 = ""
Stu_sex = ""
Stu_tel = ""
Stu_birth = ""
Stu_address = ""
Stu_memo = ""
End Sub
Private Sub stu_class1_lostfocus()
initStudentNo
End Sub
'Private Sub stu_no1_click()
'getStudentInfo
'End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -