《学生成绩管理系统VB程序.docx》由会员分享,可在线阅读,更多相关《学生成绩管理系统VB程序.docx(10页珍藏版)》请在三一办公上搜索。
1、学生成绩管理系统VB程序登陆 登陆 Private Sub cmdLogin_Click If txtUser.Text = Then MsgBox (请输入用户名!) txtUser.SetFocus Else Call openconn sql = select * from login where username= & Trim(txtUser.Text) & and password= & Trim(txtPwd.Text) & rs.Open sql, conn, adOpenDynamic, adLockOptimistic If rs.EOF Then MsgBox 用户不存在
2、! Else Unload Me frmMain.Show End If End If End Sub 退出 Private Sub cmdRegister_Click Unload Me End Sub 功能选择 选课管理 Private Sub cmdChoice_Click frmChoice.Show Unload Me End Sub 退出 Private Sub cmdExit_Click End End Sub 查询 Private Sub cmdFind_Click frmFind.Show Unload Me End Sub 成绩管理 Private Sub cmdGrade
3、_Click frmGrade.Show Unload Me End Sub 学生管理 Private Sub cmdStu_Click frmStu.Show Unload Me End Sub 学生管理 添加 Private Sub cmdAdd_Click frmAddStu.Show Unload Me End Sub 删除 Private Sub cmdDel_Click rs.Delete MsgBox (删除成功!) End Sub 编辑 Private Sub cmdEdit_Click frmEditStu.Show Unload Me End Sub 查找 Private
4、Sub cmdFind_Click 查询功能 If cboFind.Text = 学号 Then If txtInput.Text = Then MsgBox (学号输入不能为空!) txtInput.SetFocus Else Dim sql1 As String Set rs1 = New ADODB.Recordset sql1 = select * from stuInfo where ID= & txtInput.Text & rs1.CursorLocation = adUseClient rs1.Open sql1, conn, adOpenDynamic, adLockOpti
5、mistic, adCmdText If rs.EOF Then MsgBox (查不到相关信息) txtInput.SetFocus Else Set DataGrid1.DataSource = rs1 DataGrid1.Refresh End If End If Else If txtInput.Text = Then MsgBox (姓名输入不能为空!) txtInput.SetFocus Else Dim sql2 As String Set rs2 = New ADODB.Recordset sql2 = select * from stuInfo where name= & t
6、xtInput.Text & rs2.CursorLocation = adUseClient rs2.Open sql2, conn, adOpenDynamic, adLockOptimistic, adCmdText If rs.EOF Then MsgBox (查不到相关信息) txtInput.SetFocus Else Set DataGrid1.DataSource = rs2 DataGrid1.Refresh End If End If End If End Sub 返回 Private Sub cmdReturn_Click frmMain.Show Unload Me E
7、nd Sub 输出窗口 Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) txtInput.Text = DataGrid1.Columns.Item(4) 获取选中行的第5列数据 End Sub 窗体 Private Sub Form_Load Dim sql As String Set conn = New ADODB.Connection Set rs = New ADODB.Recordset Call openconn sql = select * from stuInfo
8、 rs.CursorLocation = adUseClient rs.Open sql, conn, adOpenDynamic, adLockOptimistic, adCmdText Set DataGrid1.DataSource = rs datagrid绑定数据源 End Sub 成绩查询 返回 Private Sub cmdReturn_Click frmMain.Show Unload Me End Sub 确定 Private Sub Command1_Click lblGrade.Caption = Trim(cboCourse.Text) + 课程成绩 Dim sql1
9、As String Set rs1 = New ADODB.Recordset sql1 = select score.ID,score.Num,score.score from score, course where name= & cboCourse.Text & and score.Num=course.Num sql1 = select * from course rs1.CursorLocation = adUseClient rs1.Open sql1, conn, adOpenDynamic, adLockOptimistic, adCmdText Set DataGrid1.D
10、ataSource = rs1 End Sub 窗体 Private Sub Form_Load Dim sql As String Set conn = New ADODB.Connection Set rs = New ADODB.Recordset Call openconn sql = select * from course rs.Open sql, conn, adOpenDynamic, adLockOptimistic Do Until rs.EOF cboCourse.AddItem rs(name) rs.MoveNext Loop End Sub 选课管理 返回 Priv
11、ate Sub cmdReturn_Click frmMain.Show Unload Me End Sub 提交 Private Sub cmdSubmit_Click If txtID = Then MsgBox (请输入学号!) txtID.SetFocus ElseIf lstCourse.Text = Then MsgBox (请选择课程!) Else Dim sql1 As String Dim sql2, name As String Set rs2 = New ADODB.Recordset Set rs1 = New ADODB.Recordset sql1 = select
12、 score.ID, score.Num from score , course where ID= & txtID.Text & and name= & lstCourse.Text & and score.Num=course.Num name = lstCourse.Text sql2 = select Num from course where name= & name & rs1.Open sql1, conn, adOpenDynamic, adLockOptimistic rs2.Open sql2, conn, adOpenDynamic, adLockOptimistic I
13、f rs1.EOF Then rs1.AddNew rs1(ID) = txtID.Text rs1(Num) = rs2(Num) rs1.Update MsgBox (选课成功!) rs1.Close Else MsgBox (已选过该课!) End If End If End Sub 窗体 Private Sub Form_Load Dim sql As String Set conn = New ADODB.Connection Set rs = New ADODB.Recordset sql = select * from course Call openconn rs.Open s
14、ql, conn, adOpenDynamic, adLockOptimistic Do Until rs.EOF listbox控件利用循环读取课程表中的课程名 lstCourse.AddItem rs(name) rs.MoveNext Loop End Sub 查询 确定 Private Sub cmdOK_Click If txtID = Then MsgBox (学号不能为空!) txtID.SetFocus Else Dim sql As String Dim sum1, sum2 As Single Dim n As Integer Set conn = New ADODB.Co
15、nnection Set rs = New ADODB.Recordset Call openconn sql = select course.name , score.score , course.credit from score , course where score.ID= & txtID.Text & and score.Num=course.Num rs.CursorLocation = adUseClient rs.Open sql, conn, adOpenDynamic, adLockOptimistic, adCmdText Set DataGrid1.DataSourc
16、e = rs sum1 = 0 sum2 = 0 n = 0 Do While Not rs.EOF sum1 = sum1 + Val(rs(score) sum2 = sum2 + Val(rs(credit) n = n + 1 rs.MoveNext Loop lblAvg.Caption = Format(sum1 / n, 0.0) lblCredit.Caption = sum2 End If End Sub 返回 Private Sub cmdReturn_Click frmMain.Show Unload Me End Sub 修改学生信息 返回 Private Sub cm
17、dReturn_Click frmStu.Show Unload Me End Sub 提交 Private Sub cmdSubmit_Click If txtID.Text = Then MsgBox (学号不能为空!) txtID.SetFocus ElseIf txtName.Text = Then MsgBox (姓名不能为空!) txtName.SetFocus ElseIf txtSex.Text = Then MsgBox (学分不能为空!) txtSex.SetFocus ElseIf txtAge.Text = Then MsgBox (年龄不能为空!) txtAge.Se
18、tFocus Else Dim sql As String Set conn = New ADODB.Connection Set rs = New ADODB.Recordset Call openconn sql = select * from stuInfo where ID= & txtID.Text & rs.Open sql, conn, adOpenDynamic, adLockOptimistic If Not rs.EOF Then 判断学号是否存在 rs(name) = txtName.Text rs(sex) = txtSex.Text rs(age) = txtAge.
19、Text rs(pro) = cboPro.Text rs.Update MsgBox (修改成功!) Else MsgBox (学号不存在!) End If End If End Sub 窗体 Private Sub Form_Load txtID = rs(ID) txtName = rs(name) txtSex = rs(sex) txtAge = rs(age) cboPro.Text = rs(pro) End Sub 添加学生 返回 Private Sub cmdReset_Click frmStu.Show Unload Me End Sub 提交 Private Sub cm
20、dSubmit_Click If txtID.Text = Then MsgBox (学号不能为空!) txtID.SetFocus ElseIf txtName.Text = Then MsgBox (请输入姓名!) txtName.SetFocus ElseIf txtSex.Text = Then MsgBox (请输入性别!) txtSex.SetFocus ElseIf txtAge.Text = Then MsgBox (年龄不能为空!) txtAge.SetFocus Else Dim sql As String Set conn = New ADODB.Connection S
21、et rs = New ADODB.Recordset Call openconn sql = select * from stuInfo where ID= & txtID.Text & rs.Open sql, conn, adOpenDynamic, adLockOptimistic If rs.EOF Then 判断学号是否存在 rs.AddNew rs(ID) = txtID.Text rs(name) = txtName.Text rs(sex) = txtSex.Text rs(age) = txtAge.Text rs(pro) = cboPro.Text rs.Update MsgBox (添加成功!) frmStu.Show Unload Me Else MsgBox (学号已存在!) End If End If End Sub