1、数据库技术课程设计学生成绩管理系统程序附 录用户登陆窗口代码:Dim username As String, userpass As StringPrivate Sub Command1_Click()Adodc1.Recordset.MoveFirstAdodc1.Recordset.Find (userID= & Text1 & )If Adodc1.Recordset.EOF ThenMsgBox 无此用户,请重新输入!Exit SubElseabc = Adodc1.Recordset.Fields(1)If Text2 = Trim(abc) ThenMsgBox 欢迎使用本系统,点
2、击进入!, vbOKOnly, 登陆Me.HideForm2.ShowElseMsgBox 用户名或密码不正确,请重新输入!Text1 = Text2 = Exit SubEnd IfEnd IfEnd SubPrivate Sub Command2_Click()EndEnd Sub添加统计代码:Private Sub Command1_Click()Adodc1.Recordset.AddNewText1 = InputBox(请输入学生学号, 添加学号)Text2 = InputBox(请输入学生姓名, 添加姓名)Text3 = InputBox(请输入学生性别, 添加性别)Text4
3、= InputBox(请输入学生年纪, 添加年纪)If Not IsNumeric(Text4) ThenMsgBox 请输入数值Text4.SetFocusEnd IfText5 = InputBox(请输入学生系别, 添加系别)resu = MsgBox(确定添加到数据库, vbOKCancel, 确定添加)If resu = vbOK ThenAdodc1.Recordset.UpdateElseAdodc1.Recordset.DeleteEnd IfEnd SubPrivate Sub Command2_Click()Me.HideForm2.ShowEnd Sub学生查询代码:Pr
4、ivate Sub Command1_Click()If Text1 = ThenMsgBox 请输入查询条件Text1.SetFocusEnd IfIf Option1.Value = True ThenAdodc1.Recordset.Find (sno= & Text1 & )If Adodc1.Recordset.EOF Then MsgBox 没有该学生ElseIf Option2.Value = True ThenAdodc1.Recordset.Find (sname= & Text1 & )If Adodc1.Recordset.EOF Then MsgBox 没有该学生End
5、 IfEnd SubPrivate Sub Option1_Click()Text2 = Adodc1.Recordset.MoveFirstEnd SubPrivate Sub Option2_Click()Text1 = Adodc1.Recordset.MoveFirstEnd Sub成绩查询代码:Private Sub Command1_Click()If Text4 = ThenMsgBox 请输入查询学号Text4.SetFocus End IfAdodc1.Recordset.MoveFirstabcd = Sno= & Text4 & Adodc1.Recordset.Find
6、 (abcd)If Adodc1.Recordset.EOF ThenMsgBox 没有该学生统计Text4.SetFocusEnd IfEnd SubPrivate Sub Text4_Change()If Len(Text4) 0 ThenCommand1.Enabled = TrueElseCommand1.Enabled = FalseEnd IfEnd Sub修改统计代码:Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adSta
7、tus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)Adodc1.Caption = Adodc1.Recordset.AbsolutePosition & / & Adodc1.Recordset.RecordCountEnd SubPrivate Sub Command1_Click(Index As Integer) Select Case Index Case 0 Adodc1.Recordset.MoveFirst 第一条 Case 1 Adodc1.Recordset.MovePrevious 上一条
8、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.MoveLast 最终一条 Case 4 Dim mno As String mno = InputBox(请输入学号, 查找窗) 将输入值存到变量内 Adodc1.Recordset.MoveFirst 移动统计指针到第一条统计上 Adodc1.Reco
9、rdset.Find (sno= & mno & ) 用.Find方法查找指定科目 If Adodc1.Recordset.EOF Then MsgBox 无此学号! & Adodc1.Recordset.AbsolutePosition, , 提醒 End SelectEnd SubPrivate Sub Command2_Click()Adodc1.Recordset.UpdateEnd Sub成绩添加代码:Private Sub Command1_Click()Dim adc As StringAdodc1.Recordset.AddNewa: Text1 = InputBox(输入学生
10、学号, 添加成绩)mm = Len(Text1)For i = 1 To mmabc = Mid(Text1, i, 1)If abc 9 ThenMsgBox 输入格式不正确请重新输入GoTo aEnd IfNext ib: Text2 = InputBox(输入课程号, 添加成绩)mm = Len(Text2)For i = 1 To mmabc = Mid(Text2, i, 1)If abc 9 ThenMsgBox 输入格式不正确请重新输入GoTo bEnd IfNext ic: Text3 = InputBox(输入学生成绩, 添加成绩)mm = Len(Text3)For i =
11、 1 To mmabc = Mid(Text3, i, 1)If abc 9 ThenMsgBox 输入格式不正确请重新输入GoTo aEnd IfNext iresu = MsgBox(确定添加数据库?, vbOKOnly, 确定添加)If resu = vbOK ThenAdodc1.Recordset.UpdateElseText1 = Text2 = Text3 = End IfEnd Sub学生档案管理代码:Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 Adodc1.Recordset.Mo
12、veFirst 第一条 Case 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.MoveLast 最终一条 Case 4 Dim mno As String mno = InputBox(请输入学号, 查找窗) 将输入值存到变量内
13、 Adodc1.Recordset.MoveFirst 移动统计指针到第一条统计上 Adodc1.Recordset.Find (sno= & mno & ) 用.Find方法查找指定科目 If Adodc1.Recordset.EOF Then MsgBox 无此学号! & Adodc1.Recordset.AbsolutePosition, , 提醒 End SelectEnd SubPrivate Sub Command2_Click()Dim abcd As StringDim find1a: If Option1.Value = Option2.Value ThenMsgBox 请选
14、择查询条件!Exit SubEnd IfIf Text6.Text = ThenMsgBox 请输入查询条件Text1.SetFocusExit SubEnd IfIf Option1.Value = True ThenAdodc1.Recordset.Find (sno= & Text6 & )If Adodc1.Recordset.EOF Then MsgBox 没有该学生ElseIf Option2.Value = True ThenAdodc1.Recordset.Find (sname= & Text6 & )If Adodc1.Recordset.EOF Then MsgBox 没
15、有该学生End IfEnd SubPrivate Sub Command3_Click()If Option3.Value = True ThenAdodc1.Recordset.UpdateText1.Locked = TrueText2.Locked = TrueText3.Locked = TrueText4.Locked = TrueText5.Locked = TrueElseAdodc1.Recordset.DeleteAdodc1.Recordset.UpdateEnd IfEnd SubPrivate Sub Option1_Click()Text6 = Adodc1.Reco
16、rdset.MoveFirstEnd SubPrivate Sub Option2_Click()Text6 = Adodc1.Recordset.MoveFirstEnd SubPrivate Sub Option3_Click()Command3.Enabled = TrueText1.Locked = FalseText2.Locked = FalseText3.Locked = FalseText4.Locked = FalseText5.Locked = FalseEnd SubPrivate Sub Option4_Click()Command3.Enabled = TrueEnd Sub