frmquerystudent.frm
来自「数据库课程设计」· FRM 代码 · 共 300 行
FRM
300 行
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmQueryStudent
Caption = "学生管理-查询"
ClientHeight = 4470
ClientLeft = 60
ClientTop = 345
ClientWidth = 6255
LinkTopic = "Form1"
ScaleHeight = 4470
ScaleWidth = 6255
StartUpPosition = 3 'Windows Default
Begin MSFlexGridLib.MSFlexGrid fgStudent
Height = 1935
Left = 120
TabIndex = 10
Top = 2400
Width = 6015
_ExtentX = 10610
_ExtentY = 3413
_Version = 393216
End
Begin VB.CommandButton cmdCancel
Caption = "返回(&C)"
Height = 375
Left = 3120
TabIndex = 9
Top = 1920
Width = 1335
End
Begin VB.CommandButton cmdOK
Caption = " 查询(&Q)"
Height = 375
Left = 1440
TabIndex = 8
Top = 1920
Width = 1335
End
Begin VB.Frame Frame1
Caption = "查询条件"
Height = 1455
Left = 120
TabIndex = 0
Top = 240
Width = 6015
Begin VB.ComboBox cboClass
Height = 315
Left = 1560
TabIndex = 7
Top = 840
Width = 1215
End
Begin VB.OptionButton optchoice
Caption = "按班级查询"
Height = 375
Index = 1
Left = 240
TabIndex = 6
Top = 840
Width = 1335
End
Begin VB.TextBox txtName
Height = 375
Left = 4560
TabIndex = 5
Top = 840
Width = 1215
End
Begin VB.TextBox txtNo
Height = 375
Left = 4560
TabIndex = 4
Top = 360
Width = 1215
End
Begin VB.OptionButton optchoice
Caption = "按姓名查询"
Height = 375
Index = 3
Left = 3120
TabIndex = 3
Top = 840
Width = 1335
End
Begin VB.OptionButton optchoice
Caption = "按学号查询"
Height = 375
Index = 2
Left = 3120
TabIndex = 2
Top = 360
Width = 1455
End
Begin VB.OptionButton optchoice
Caption = "查询全部"
Height = 375
Index = 0
Left = 240
TabIndex = 1
Top = 360
Width = 1335
End
Begin VB.Line Line1
BorderColor = &H80000005&
X1 = 3000
X2 = 3000
Y1 = 240
Y2 = 1320
End
End
End
Attribute VB_Name = "frmQueryStudent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer
'如果选择的是查询全部,进行下面的处理
If optchoice(0).Value Then
sqlStr = "select * from studentInfo"
End If
'选择的是按班级查询
If optchoice(1).Value Then
sqlStr = "select * from studentInfo where class_no='" & cboClass.Text & "'"
End If
'选择的是按学号查询
If optchoice(2).Value Then
If txtNo.Text = "" Then
MsgBox "请输入要查询的学号信息!!"
Exit Sub
Else
sqlStr = "select * from studentInfo where stu_no='" & txtNo.Text & "'"
End If
End If
'选择的是按姓名查询
If optchoice(3).Value Then
If txtName.Text = "" Then
MsgBox "请输入要查询的学生姓名!!"
Exit Sub
Else
sqlStr = "select * from studentInfo where name='" & txtName.Text & "'"
End If
End If
Set rs = ExecuteSQL(sqlStr, msgText)
If rs.RecordCount = 0 Then
MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
fgStudent.Clear
Else
fgStudent.Rows = rs.RecordCount + 1
fgStudent.Cols = 9
'Print fgStudent.Rows
'设定行高
For i = 0 To fgStudent.Rows - 1
fgStudent.RowHeight(i) = 280
Next i
'设定列的属性
fgStudent.Row = 0
For i = 0 To fgStudent.Cols - 1
fgStudent.Col = i '指定当前列为第i列
fgStudent.FixedAlignment(i) = 4 '每列内容居中显示
Select Case i
Case 0
fgStudent.ColWidth(i) = 620 '设定列宽
fgStudent.Text = "序号"
Case 1
fgStudent.ColWidth(i) = 920 '设定列宽
fgStudent.Text = "学号"
Case 2
fgStudent.ColWidth(i) = 1000 '设定列宽
fgStudent.Text = "姓名"
Case 3
fgStudent.ColWidth(i) = 700 '设定列宽
fgStudent.Text = "性别"
Case 4
fgStudent.ColWidth(i) = 700 '设定列宽
fgStudent.Text = "班级"
Case 5
fgStudent.ColWidth(i) = 1000 '设定列宽
fgStudent.Text = "出生日期"
Case 6
fgStudent.ColWidth(i) = 700 '设定列宽
fgStudent.Text = "电话"
Case 7
fgStudent.ColWidth(i) = 700 '设定列宽
fgStudent.Text = "地址"
Case 8
fgStudent.ColWidth(i) = 1000 '设定列宽
fgStudent.Text = "备注"
End Select
Next i
'rs.MoveFirst
i = 1
While (Not rs.EOF)
fgStudent.Row = i
For j = 0 To fgStudent.Cols - 1
fgStudent.Col = j '设置当前为列为第j列
fgStudent.CellAlignment = 4 '每列内容居中显示
Select Case j
Case 0
fgStudent.Text = "" & i
Case 1
fgStudent.Text = rs.Fields("stu_no")
Case 2
fgStudent.Text = rs.Fields("name")
Case 3
fgStudent.Text = rs.Fields("sex")
Case 4
fgStudent.Text = rs.Fields("class_no")
Case 5
fgStudent.Text = rs.Fields("birthdate")
Case 6
fgStudent.Text = rs.Fields("telno")
Case 7
fgStudent.Text = rs.Fields("address")
Case 8
fgStudent.Text = rs.Fields("memo")
End Select
Next j
'Print rs.Fields("bookid"), rs.Fields("bookname")
rs.MoveNext
i = i + 1
Wend
fgStudent.Visible = True
frmQueryStudent.Height = 5280
End If
rs.Close
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initClass
End Sub
Sub initClass()
Dim rstClass As ADODB.Recordset
'从数据库中读取所有班级并添加到组合列表框中
'方便录入时进行选择
sqlStr = "select className from classInfo"
Set rstClass = ExecuteSQL(sqlStr, msgText)
cboClass.Clear
If Not rstClass.EOF Then
Do While Not rstClass.EOF
cboClass.AddItem Trim(rstClass.Fields(0))
rstClass.MoveNext
Loop
cboClass.ListIndex = 0
Else
MsgBox "无班级记录,请添加班级!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstClass.Close
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?