www.pudn.com > cjg2.rar > frmQueryScore.frm
VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form QueryScore
Caption = "考试成绩查询"
ClientHeight = 4260
ClientLeft = 60
ClientTop = 345
ClientWidth = 7005
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 4260
ScaleWidth = 7005
WindowState = 2 'Maximized
Begin MSDataGridLib.DataGrid dgScore
Height = 2865
Left = 510
TabIndex = 4
Top = 825
Width = 5820
_ExtentX = 10266
_ExtentY = 5054
_Version = 393216
AllowUpdate = 0 'False
HeadLines = 1
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "自测考试成绩"
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.CommandButton cmdExit
Cancel = -1 'True
Caption = "退出"
Height = 300
Left = 4380
TabIndex = 3
Top = 255
Width = 870
End
Begin VB.CommandButton cmdOk
Caption = "确定"
Default = -1 'True
Height = 300
Left = 3345
TabIndex = 2
Top = 255
Width = 870
End
Begin VB.TextBox txtNum
Height = 300
Left = 945
TabIndex = 1
Top = 255
Width = 2160
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "学号"
Height = 180
Left = 510
TabIndex = 0
Top = 315
Width = 360
End
End
Attribute VB_Name = "QueryScore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim objScore As Recordset '用于保存成绩信息
Dim objCn As Connection '用于建立数据库联接
Private Sub cmdExit_Click()
Unload Me '关成绩查询窗体
End Sub
Private Sub cmdOk_Click()
With objScore
.MoveFirst
.Find "学号='" & Trim(txtNum) & "'"
If .EOF Then
MsgBox "学号输入错误!", vbCritical, Me.Caption
Else
'使用消息框显示学生成绩
MsgBox "学号为" & txtNum & "的学生信息如下:" & vbCrLf _
& " 姓名:" & .Fields("姓名") & vbCrLf _
& " 考号:" & .Fields("考号") & vbCrLf _
& " 班级:" & .Fields("班级") & vbCrLf _
& " 系部:" & .Fields("系部") & vbCrLf _
& " 成绩:" & .Fields("成绩"), , Me.Caption
End If
End With
End Sub
Private Sub Form_Load()
'建立数据库联接
Set objCn = New Connection '实例化联接对象
With objCn '建立数据库联接
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
"Initial Catalog=自测考试"
.Open
End With
'获取成绩信息
Set objScore = New Recordset
With objScore
Set .ActiveConnection = objCn '设置数据库联接
.CursorLocation = adUseClient '指定使用客户端游标
.Open "SELECT 姓名,学号,考号,班级信息.名称 as 班级,系部信息.名称 " _
& " as 系部,isnull(cast(成绩 as varchar),'缺考') as 成绩 " _
& "FROM 学生信息,班级信息,系部信息 WHERE 学生信息.班级=班级信息.编号 " _
& "and 学生信息.系部=系部信息.编号"
Set .ActiveConnection = Nothing '断开数据库联接
End With
Set dgScore.DataSource = objScore
End Sub
Private Sub Form_Resize()
'根据窗口大小调整数据网格大小
dgScore.Width = Abs(Me.Width - 2 * dgScore.Left)
dgScore.Height = Abs(Me.Height - dgScore.Top - 800)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objCn = Nothing
Set objScore = Nothing
End Sub