📄 成绩查询.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form search_grade
BorderStyle = 1 'Fixed Single
Caption = "成绩查询"
ClientHeight = 5460
ClientLeft = 3765
ClientTop = 2805
ClientWidth = 8205
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5460
ScaleWidth = 8205
Begin MSAdodcLib.Adodc Adodc1
Height = 330
Left = 3120
Top = 5280
Visible = 0 'False
Width = 1695
_ExtentX = 2990
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
OLEDBString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = "sa"
Password = "manager"
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.ListBox List2
Height = 3660
Left = 4440
TabIndex = 9
Top = 1440
Width = 3375
End
Begin VB.CommandButton Command2
Caption = "查询"
Height = 495
Left = 6480
TabIndex = 8
Top = 840
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 5280
TabIndex = 7
Top = 240
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "查询"
Height = 495
Left = 2520
TabIndex = 5
Top = 240
Width = 1215
End
Begin VB.ComboBox Combo1
Height = 300
Left = 1080
Style = 2 'Dropdown List
TabIndex = 2
Top = 240
Width = 975
End
Begin VB.ListBox List1
Height = 3660
Left = 240
TabIndex = 0
Top = 1440
Width = 3375
End
Begin VB.Label student_name
Height = 255
Left = 4320
TabIndex = 10
Top = 960
Width = 1455
End
Begin VB.Label Label4
Caption = "学 号"
Height = 255
Left = 4320
TabIndex = 6
Top = 360
Width = 735
End
Begin VB.Label sub_name
Height = 255
Left = 1080
TabIndex = 4
Top = 840
Width = 2655
End
Begin VB.Label Label2
Caption = "课程名称"
Height = 255
Left = 240
TabIndex = 3
Top = 840
Width = 735
End
Begin VB.Label Label1
Caption = "课程编号"
Height = 255
Left = 240
TabIndex = 1
Top = 360
Width = 735
End
Begin VB.Line Line1
X1 = 4080
X2 = 4080
Y1 = 240
Y2 = 5040
End
End
Attribute VB_Name = "search_grade"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public rs As New ADODB.Recordset
Public adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。
Public sub_id As String
Public stu_no As String
'选择课程编号后,课程名称显示出来
Private Sub Combo1_Click()
Dim i As Integer
sub_id = Combo1.Text
If Len(sub_id) <> 0 Then
adoconn.Open
rs.Open "select * from subject where id='" & sub_id & "'", adoconn
If sub_id = rs.Fields("id") Then
sub_name.Caption = rs.Fields("name")
End If
rs.Close
adoconn.Close
End If
End Sub
'按课程编号查询
Private Sub Command1_Click()
List1.clear
'获取编号
sub_id = Combo1.Text
If Len(sub_id) = 0 Then
MsgBox "请选择课程编号!"
Combo1.SetFocus
Exit Sub
End If
'查询数据并显示
adoconn.Open
rs.Open "select * from grade where sub_id='" & sub_id & "'", adoconn
'没有任何数据
If rs.RecordCount = 0 Then
MsgBox "该科目没有任何成绩!"
List1.clear
rs.Close
adoconn.Close
Exit Sub
End If
'找到数据
List1.AddItem Space(3) & "学号" & Space(12) & "成绩"
Dim i As Integer
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
List1.AddItem rs.Fields("stu_no") & Space(18) & rs.Fields("grade")
rs.MoveNext
Next i
rs.Close
adoconn.Close
End Sub
'按学号查询
Private Sub Command2_Click()
stu_no = Text1.Text
If Len(stu_no) = 0 Then
MsgBox "请输入学号!"
Text1.SetFocus
Exit Sub
End If
adoconn.Open
rs.Open "select * from stu where no='" & stu_no & "'", adoconn
If rs.RecordCount = 0 Then
MsgBox "没有该学生信息!"
student_name.Caption = ""
Text1.Text = ""
List2.clear
Text1.SetFocus
rs.Close
adoconn.Close
Exit Sub
End If
student_name.Caption = "姓名:" & rs.Fields("name")
rs.Close
rs.Open "select * from grade where stu_no='" & stu_no & "'", adoconn
If rs.RecordCount = 0 Then
MsgBox "没有该学生的成绩!"
List2.clear
Text1.Text = ""
student_name = ""
Text1.SetFocus
rs.Close
adoconn.Close
Exit Sub
End If
rs.Close
Dim i As Integer
List2.clear
List2.AddItem Space(2) & "课程名称" & Space(15) & "成绩"
rs.Open "select name,grade from subject,grade where id=sub_id and stu_no='" & stu_no & "'", adoconn
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
List2.AddItem Format(rs.Fields("name"), "####################") & Format(rs.Fields("grade"), "@@@@@@@@@@@@@@@@@@@@@@@")
rs.MoveNext
Next i
rs.Close
adoconn.Close
End Sub
'打开窗体时,加载课程编号下拉列表
Private Sub Form_Load()
adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
adoconn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
Dim i As Integer
rs.Open "select * from subject", adoconn
If rs.RecordCount = 0 Then
rs.Close
adoconn.Close
Exit Sub
End If
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs.Fields("id")
rs.MoveNext
Next i
rs.Close
adoconn.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -