SQL 数据库课程设计学生成绩系统
DataGrid1.AllowDelete = False DataGrid1.AllowUpdate = False End Sub
4.6. 选课模块 4.6.1 4.6.2
4.6.2.1.
说明
该模块为一个班级选课。
课程添加窗体
用于课程的添加和查询
窗体设计
SQL 数据库课程设计学生成绩系统
4.6.2.2. 代码设计
添加(Command1)处理(Click)
Private Sub Command1_Click()
Dim s1 As String, s2 As String On Error Resume Next
If Text1.Text = "" Or Text2.Text = "" Then MsgBox ("输入不能为空") Exit Sub End If
s1 = "select * from 班级课程表 where 班级名称='"
s2 = Text1.Text & "' and 课程名称='" & Text2.Text & "'" Adodc1.RecordSource = s1 & s2 Adodc1.Refresh
If Adodc1.Recordset.EOF = False Then Text1.SetFocus
MsgBox "该记录已存在,请重新输入", , "警告" Exit Sub End If
s1 = "select * from 班级课程表" Adodc1.RecordSource = s1 Adodc1.Refresh
Adodc1.Recordset.MoveLast Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("班级名称") = Text1.Text Adodc1.Recordset.Fields("课程名称") = Text2.Text Adodc1.Recordset.Update Adodc1.Refresh
s1 = "select 课程名称 from 班级课程表 where 班级名称='" & Text1.Text & "'" Adodc1.RecordSource = s1 Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset Text2.SetFocus Text2.Text = "" Exit Sub End Sub
查询(Command2)处理(Click)
Private Sub Command2_Click() Dim s1 As String
s1 = "select 课程名称 from 班级课程表 where 班级名称='" & Text1.Text & "'"
SQL 数据库课程设计学生成绩系统
Adodc1.RecordSource = s1 Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset End Sub
退出(Command3)处理(Click)
Private Sub Command3_Click() Unload Me End Sub
窗体装载处理程序(Load)
Private Sub Form_Load()
DataGrid1.AllowAddNew = False DataGrid1.AllowDelete = False DataGrid1.AllowUpdate = False End Sub
4.6.3
4.6.3.1.
课程删除窗体
窗体设计
SQL 数据库课程设计学生成绩系统
4.6.3.2. 代码设计
退出(Command1)处理(Click)
Private Sub Command1_Click() Unload Me End Sub
数据列表框(DataList1)处理(Click)
Private Sub DataList1_Click() Dim s1 As String
s1 = "select * from 班级课程表 where 班级名称='" & DataList1.Text & "'" Adodc2.RecordSource = s1 Adodc2.Refresh
Set DataGrid1.DataSource = Adodc2 End Sub
窗体装载处理程序(Load)
Private Sub Form_Load()
DataGrid1.AllowDelete = True DataGrid1.AllowUpdate = True DataGrid1.AllowAddNew = False End Sub
4.7. 成绩管理模块 4.7.1 4.7.2
4.7.2.1.
说明
进行学生成绩的录入及查询。
成绩录入窗体
进行学生成绩的添加、修改及删除。
窗体设计
SQL 数据库课程设计学生成绩系统
4.7.2.2. 代码设计
录入(Command1)处理(Click)
Private Sub Command1_Click()
Dim s1 As String, s2 As String, s3 As String On Error Resume Next
s1 = "select * from 学生成绩表 "
s2 = "where 学号='" & List2.Text & "' and " s3 = "课程名称='" & List1.Text & "'"
Adodc3.RecordSource = s1 & s2 & s3 Adodc3.Refresh
If Adodc3.Recordset.EOF = False Then
Adodc3.Recordset.Fields(2) = Val(Text1.Text) Else
Adodc3.Recordset.MoveLast Adodc3.Recordset.AddNew
Adodc3.Recordset.Fields(0) = List2.Text Adodc3.Recordset.Fields(1) = List1.Text
Adodc3.Recordset.Fields(2) = Val(Text1.Text) End If
Adodc3.Recordset.Update Adodc3.Refresh
s1 = "select 学号,成绩 from 学生成绩表 where 课程名称='" & List1.Text & "'" s2 = " and 学号 in (select 学号 from 学生基本信息表 "
SQL 数据库课程设计学生成绩系统
s3 = "where 班级名称 ='" & DataList1.Text & "')" Adodc3.RecordSource = s1 & s2 & s3 Adodc3.Refresh
Set DataGrid1.DataSource = Adodc3 End Sub
退出(Command1)处理(Click )
Private Sub Command2_Click() Unload Me End Sub
数据列表框(DataList1)处理(Click)
Private Sub DataList1_Click()
Dim s1 As String, s2 As String
Set DataGrid1.DataSource = Nothing
s1 = "select 课程名称 from 班级课程表 "
s2 = "where 班级名称='" & DataList1.Text & "'" Adodc2.RecordSource = s1 & s2 Adodc2.Refresh
If Adodc2.Recordset.EOF = True Then
MsgBox "请在班级课程表里添加该班级的课程名称" Exit Sub End If
List1.Clear
Adodc2.Recordset.MoveFirst
Do While Adodc2.Recordset.EOF = False
List1.AddItem Adodc2.Recordset.Fields(0) Adodc2.Recordset.MoveNext Loop
s1 = "select 学号 from 学生基本信息表 "
s2 = "where 班级名称='" & DataList1.Text & "'" Adodc2.RecordSource = s1 & s2 Adodc2.Refresh
If Adodc2.Recordset.EOF = True Then MsgBox "请在学生信息表里添加该班级" Exit Sub End If
List2.Clear
Adodc2.Recordset.MoveFirst
Do While Adodc2.Recordset.EOF = False
List2.AddItem Adodc2.Recordset.Fields(0)