1、《数据库技术》课程设计 《学生成绩管理系统》程序 附 录 用户登陆窗口代码: Dim username As String, userpass As String Private Sub Command1_Click() Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find ("userID='" & Text1 & "'") If Adodc1.Recordset.EOF Then MsgBox "无此用户,请重新输入!" Exit Sub Else abc = Adodc1.Recordset.Fields(1)
2、If Text2 = Trim(abc) Then MsgBox "欢迎使用本系统,点击进入!", vbOKOnly, "登陆" Me.Hide Form2.Show Else MsgBox "用户名或密码不正确,请重新输入!" Text1 = "" Text2 = "" Exit Sub End If End If End Sub Private Sub Command2_Click() End End Sub 添加统计代码: Private Sub Command1_Click() Adodc1.Recordset.AddNew Text1 = Inpu
3、tBox("请输入学生学号", "添加学号") Text2 = InputBox("请输入学生姓名", "添加姓名") Text3 = InputBox("请输入学生性别", "添加性别") Text4 = InputBox("请输入学生年纪", "添加年纪") If Not IsNumeric(Text4) Then MsgBox "请输入数值" Text4.SetFocus End If Text5 = InputBox("请输入学生系别", "添加系别") resu = MsgBox("确定添加到数据库", vbOKCancel, "确定添加") If resu =
4、vbOK Then Adodc1.Recordset.Update Else Adodc1.Recordset.Delete End If End Sub Private Sub Command2_Click() Me.Hide Form2.Show End Sub 学生查询代码: Private Sub Command1_Click() If Text1 = "" Then MsgBox "请输入查询条件" Text1.SetFocus End If If Option1.Value = True Then Adodc1.Recordset.Find ("s
5、no='" & Text1 & " '") If Adodc1.Recordset.EOF Then MsgBox "没有该学生" ElseIf Option2.Value = True Then Adodc1.Recordset.Find ("sname='" & Text1 & " '") If Adodc1.Recordset.EOF Then MsgBox "没有该学生" End If End Sub Private Sub Option1_Click() Text2 = "" Adodc1.Recordset.MoveFirst End Sub Private
6、Sub Option2_Click() Text1 = "" Adodc1.Recordset.MoveFirst End Sub 成绩查询代码: Private Sub Command1_Click() If Text4 = "" Then MsgBox "请输入查询学号" Text4.SetFocus End If Adodc1.Recordset.MoveFirst abcd = "Sno='" & Text4 & " '" Adodc1.Recordset.Find (abcd) If Adodc1.Recordset.EOF Then MsgB
7、ox "没有该学生统计" Text4.SetFocus End If End Sub Private Sub Text4_Change() If Len(Text4) > 0 Then Command1.Enabled = True Else Command1.Enabled = False End If End Sub 修改统计代码: Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADOD
8、B.EventStatusEnum, ByVal pRecordset As ADODB.Recordset) Adodc1.Caption = Adodc1.Recordset.AbsolutePosition & "/" & Adodc1.Recordset.RecordCount End Sub Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 Adodc1.Recordset.MoveFirst ' 第一条 Case
9、 1 Adodc1.Recordset.MovePrevious ' 上一条 If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst Case 2 Adodc1.Recordset.MoveNext ' 下一条 If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast Case 3 Adodc1.Recordset.Move
10、Last ' 最终一条 Case 4 Dim mno As String mno = InputBox("请输入学号", "查找窗") ' 将输入值存到变量内 Adodc1.Recordset.MoveFirst ' 移动统计指针到第一条统计上 Adodc1.Recordset.Find ("sno='" & mno & "'") '用.Find方法查找指定科目 If Adodc1.Recordset.EOF Then MsgBox "无此学号!
11、" & Adodc1.Recordset.AbsolutePosition, , "提醒" End Select End Sub Private Sub Command2_Click() Adodc1.Recordset.Update End Sub 成绩添加代码: Private Sub Command1_Click() Dim adc As String Adodc1.Recordset.AddNew a: Text1 = InputBox("输入学生学号", "添加成绩") mm = Len(Text1) For i = 1 To mm abc = Mi
12、d(Text1, i, 1) If abc < "0" Or abc > "9" Then MsgBox "输入格式不正确请重新输入" GoTo a End If Next i b: Text2 = InputBox("输入课程号", "添加成绩") mm = Len(Text2) For i = 1 To mm abc = Mid(Text2, i, 1) If abc < "0" Or abc > "9" Then MsgBox "输入格式不正确请重新输入" GoTo b End If Next i c: Text3 = InputBox("输入学生成绩",
13、"添加成绩") mm = Len(Text3) For i = 1 To mm abc = Mid(Text3, i, 1) If abc < "0" Or abc > "9" Then MsgBox "输入格式不正确请重新输入" GoTo a End If Next i resu = MsgBox("确定添加数据库??", vbOKOnly, "确定添加") If resu = vbOK Then Adodc1.Recordset.Update Else Text1 = "" Text2 = "" Text3 = "" End If End Sub 学生档
14、案管理代码: Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 Adodc1.Recordset.MoveFirst ' 第一条 Case 1 Adodc1.Recordset.MovePrevious ' 上一条 If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst Case 2
15、 Adodc1.Recordset.MoveNext ' 下一条 If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast Case 3 Adodc1.Recordset.MoveLast ' 最终一条 Case 4 Dim mno As String mno = InputBox("请输入学号", "查找窗") ' 将输入值存到变量内 Adodc1.Recordset.MoveFirst
16、 ' 移动统计指针到第一条统计上 Adodc1.Recordset.Find ("sno='" & mno & "'") '用.Find方法查找指定科目 If Adodc1.Recordset.EOF Then MsgBox "无此学号!" & Adodc1.Recordset.AbsolutePosition, , "提醒" End Select End Sub Private Sub Command2_Click() Dim abcd As String Dim find1 a: If Option1.
17、Value = Option2.Value Then MsgBox "请选择查询条件!" Exit Sub End If If Text6.Text = "" Then MsgBox "请输入查询条件" Text1.SetFocus Exit Sub End If If Option1.Value = True Then Adodc1.Recordset.Find ("sno='" & Text6 & " '") If Adodc1.Recordset.EOF Then MsgBox "没有该学生" ElseIf Option2.Value = True Then A
18、dodc1.Recordset.Find ("sname='" & Text6 & " '") If Adodc1.Recordset.EOF Then MsgBox "没有该学生" End If End Sub Private Sub Command3_Click() If Option3.Value = True Then Adodc1.Recordset.Update Text1.Locked = True Text2.Locked = True Text3.Locked = True Text4.Locked = True Text5.Locked = True
19、 Else Adodc1.Recordset.Delete Adodc1.Recordset.Update End If End Sub Private Sub Option1_Click() Text6 = "" Adodc1.Recordset.MoveFirst End Sub Private Sub Option2_Click() Text6 = "" Adodc1.Recordset.MoveFirst End Sub Private Sub Option3_Click() Command3.Enabled = True Text1.Locked = False Text2.Locked = False Text3.Locked = False Text4.Locked = False Text5.Locked = False End Sub Private Sub Option4_Click() Command3.Enabled = True End Sub
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818