📄 stumodi.frm
字号:
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.Label Label9
BackStyle = 0 'Transparent
Caption = "Label9"
Height = 375
Left = 3480
TabIndex = 25
Top = 4200
Width = 5655
End
Begin VB.Label Label10
BackStyle = 0 'Transparent
Caption = "学号:"
Height = 495
Left = 3960
TabIndex = 24
Top = 5040
Width = 735
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "学号:"
Height = 495
Left = 675
TabIndex = 20
Top = 1200
Width = 615
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "性别:"
Height = 255
Left = 675
TabIndex = 19
Top = 2400
Width = 735
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "班级编号:"
Height = 375
Left = 360
TabIndex = 18
Top = 3600
Width = 975
End
Begin VB.Label Label5
BackStyle = 0 'Transparent
Caption = "姓名:"
Height = 375
Left = 675
TabIndex = 17
Top = 1800
Width = 1335
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Caption = "生日:"
Height = 495
Left = 675
TabIndex = 16
Top = 2880
Width = 1215
End
Begin VB.Label Label7
BackStyle = 0 'Transparent
Caption = "系编号:"
Height = 255
Left = 555
TabIndex = 15
Top = 4080
Width = 1215
End
Begin VB.Label Label8
BackStyle = 0 'Transparent
Caption = "籍贯:"
Height = 255
Left = 675
TabIndex = 14
Top = 4680
Width = 495
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 = 3720
TabIndex = 13
Top = 120
Width = 2895
End
End
Attribute VB_Name = "stumodi"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim WithEvents MyRs As ADODB.Recordset
Attribute MyRs.VB_VarHelpID = -1
Dim myrs1 As ADODB.Recordset
Dim myrs2 As ADODB.Recordset
Dim myrs3 As ADODB.Recordset
Dim str As String
Dim myconn As ADODB.Connection
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 "student", myconn, adOpenStatic, adLockOptimistic, adCmdTable
Set MyRs = New ADODB.Recordset
MyRs.ActiveConnection = myconn
MyRs.Source = "student"
MyRs.CursorLocation = adUseClient
MyRs.CursorType = adOpenStatic
MyRs.Open , , , adLockOptimistic
Set DataGrid1.DataSource = MyRs
DataGrid1.Columns(0).Caption = "学号"
DataGrid1.Columns(1).Caption = "姓名"
DataGrid1.Columns(2).Caption = "性别"
DataGrid1.Columns(3).Caption = "班级编号"
DataGrid1.Columns(4).Caption = "院系编号"
DataGrid1.Columns(5).Caption = "生日"
DataGrid1.Columns(6).Caption = "籍贯"
DataGrid1.Columns(3).Width = 1100
DataGrid1.Columns(5).Width = 1200
DataGrid1.Columns(6).Width = 1000
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
Combo1.AddItem "男"
Combo1.AddItem "女"
End Sub
Private Sub XpButton1_Click()
MyRs.MoveFirst
End Sub
Private Sub XpButton2_Click()
MyRs.MovePrevious
If MyRs.BOF = True Then
MyRs.MoveFirst
End If
End Sub
Private Sub XpButton3_Click()
MyRs.MoveNext
If MyRs.EOF = True Then
MyRs.MoveLast
End If
End Sub
Private Sub XpButton4_Click()
MyRs.MoveLast
End Sub
Private Sub XpButton5_Click()
MyRs.Close
myconn.Close
Unload Me
End Sub
Private Sub MyRs_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
Label9.Caption = "当前记录/记录总数:" & MyRs.AbsolutePosition & "/" & MyRs.RecordCount
Text1.Locked = False
If MyRs.EOF = True Then
MyRs.MoveLast
Else
If MyRs.BOF = True Then
MyRs.MoveFirst
Else
Text1.Text = MyRs.Fields(0)
Text2.Text = MyRs.Fields(1)
Text3.Text = MyRs.Fields(6)
Combo1.Text = MyRs.Fields(2)
Combo2.Text = MyRs.Fields(3)
Combo3.Text = MyRs.Fields(4)
txtBirth.Mask = ""
txtBirth.Text = Format$(MyRs.Fields(5))
End If
End If
Text1.Locked = True
End Sub
Private Sub XpButton6_Click()
On Error GoTo DbnotOpen
If Val(txtBirth.Text) <> 0 Then
If Not IsDate(txtBirth.Text) Then
MsgBox "生日不是有效日期,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
Exit Sub
End If
End If
If Len(Trim(Text1.Text)) = 0 Then
MsgBox "学生信息没有填写完整!", vbOKOnly + vbExclamation, "错误提示"
Else
If Trim(Combo1.Text) <> "男" Then
If Trim(Combo1.Text) <> "女" Then
MsgBox "性别填写有错误!", vbOKOnly + vbExclamation, "错误提示"
Exit Sub
End If
End If
str = "select ID from CLASS where ID='" & Trim(Combo2.Text) & "'"
Set myrs1 = myconn.Execute(str)
If myrs1.EOF Then
MsgBox "班级编号填写有错误!", vbOKOnly + vbExclamation, "错误提示"
Exit Sub
End If
str = "select ID from DEPARTMENT where ID='" & Trim(Combo3.Text) & "'"
Set myrs1 = myconn.Execute(str)
If myrs1.EOF Then
MsgBox "院系编号填写有错误!", vbOKOnly + vbExclamation, "错误提示"
Exit Sub
End If
With MyRs
.Fields(0) = Trim(Text1.Text)
.Fields(1) = Trim(Text2.Text)
.Fields(2) = Trim(Combo1.Text)
.Fields(3) = Trim(Combo2.Text)
.Fields(4) = Trim(Combo3.Text)
.Fields(5) = Format(txtBirth.Text, "yyyy-mm-dd")
.Fields(6) = Trim(Text3.Text)
.Update
End With
MsgBox "学生信息修改成功!", vbOKOnly + vbInformation, "提示信息"
End If
DbnotOpen:
If Err = -2147352571 Then
MsgBox "生日不是有效日期,请重新输入!", vbInformation, "提示"
txtBirth.SetFocus
txtBirth.Text = "____-__-__"
Exit Sub
End If
If Err = -2147217887 Then
MsgBox " 输入的学号长度或姓名或者籍贯越界,请重新输入!", vbInformation, "提示信息"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Exit Sub
End If
End Sub
Private Sub XpButton7_Click()
'MyRs.MoveFirst
'MyRs.Find "ID=" + "'" + Trim(Text4.Text) + "'"
str = "select ID from student where ID='" & Trim(Text4.Text) & "'"
Set myrs3 = myconn.Execute(str)
If myrs3.EOF Then
MsgBox "数据库中不存在这个学生的注册信息!", vbOKOnly + vbExclamation, "错误提示"
Text4.Text = ""
Text4.SetFocus
Else
MyRs.MoveFirst
MyRs.Find "ID=" + "'" + Trim(Text4.Text) + "'"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -