⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 课程查询.frm

📁 初学vb,做的第一个系统.一个星期内看vb并做完这个系统的.
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form search_subject 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "课程查询"
   ClientHeight    =   4755
   ClientLeft      =   4080
   ClientTop       =   3240
   ClientWidth     =   7065
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4755
   ScaleWidth      =   7065
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   735
      Left            =   2760
      Top             =   2040
      Visible         =   0   'False
      Width           =   1575
      _ExtentX        =   2778
      _ExtentY        =   1296
      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 List1 
      Height          =   3300
      Left            =   240
      TabIndex        =   5
      Top             =   840
      Width           =   6495
   End
   Begin VB.CommandButton Command2 
      Caption         =   "查询"
      Height          =   375
      Left            =   5760
      TabIndex        =   4
      Top             =   240
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "查询"
      Height          =   375
      Left            =   2520
      TabIndex        =   2
      Top             =   240
      Width           =   855
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   4560
      TabIndex        =   3
      Top             =   240
      Width           =   975
   End
   Begin VB.ComboBox Combo1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   1080
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label showinfo 
      Height          =   375
      Left            =   240
      TabIndex        =   7
      Top             =   4320
      Width           =   6495
   End
   Begin VB.Line Line1 
      X1              =   3600
      X2              =   3600
      Y1              =   120
      Y2              =   720
   End
   Begin VB.Label Label2 
      Caption         =   "授课教师"
      Height          =   255
      Left            =   3720
      TabIndex        =   6
      Top             =   360
      Width           =   735
   End
   Begin VB.Label Label1 
      Caption         =   "课程类别"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   735
   End
End
Attribute VB_Name = "search_subject"
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 对象代表了打开与数据源的连接。
'按课程类别查询
Private Sub Command1_Click()
    List1.clear
    showinfo.Caption = ""
    Dim type_name As String
    type_name = Combo1.Text
    If Len(type_name) = 0 Then
        MsgBox "请选择课程类别!"
        Combo1.SetFocus
        Exit Sub
    End If
    
    adoconn.Open
    rs.Open "select subject.id as id1,subject.name as name1,teacher,addr from type,subject where subject.type=type.id and type.name='" & type_name & "'", adoconn
    If rs.RecordCount = 0 Then
        MsgBox "没有任何属于该类别的科目!"
        rs.Close
        adoconn.Close
        Combo1.SetFocus
        Exit Sub
    End If
    
    List1.AddItem "课程编号         课程名称         授课教师      上课地点     "
    Dim i As Integer
    rs.MoveFirst
    For i = 0 To rs.RecordCount - 1
        List1.AddItem rs.Fields("id1") & Space(15) & rs.Fields("name1") & Space(12) & rs.Fields("teacher") & Space(12) & rs.Fields("addr")
        rs.MoveNext
    Next i
    rs.Close
    adoconn.Close
End Sub
'按教师姓名查询
Private Sub Command2_Click()
    List1.clear
    Dim teacher_name As String
    teacher_name = Text1.Text
    If Len(teacher_name) = 0 Then
        MsgBox "请输入授课教师姓名!"
        Text1.SetFocus
        Exit Sub
    End If
    
    adoconn.Open
    rs.Open "select subject.id as id1,subject.name as name1,type.name as name2,addr from subject,type where subject.type=type.id and teacher='" & teacher_name & "'", adoconn
    If rs.RecordCount = 0 Then
        MsgBox "没有该教师授的课!"
        Text1.Text = ""
        Text1.SetFocus
        rs.Close
        adoconn.Close
        Exit Sub
    End If
    
    List1.AddItem "课程编号        课程名称        课程类别        上课地点  "
    rs.MoveFirst
    Dim i As Integer
    For i = 0 To rs.RecordCount - 1
        List1.AddItem rs.Fields("id1") & Space(15) & rs.Fields("name1") & Space(12) & rs.Fields("name2") & Space(12) & rs.Fields("addr")
        rs.MoveNext
    Next i
    rs.Close
    adoconn.Close
End Sub

Private Sub Form_Load()
    '加载课程类别列表
    adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    
    adoconn.Open
    rs.Open "select * from type", adoconn
    rs.MoveFirst
    Dim i As Integer
    For i = 0 To rs.RecordCount - 1
        Combo1.AddItem rs.Fields("name")
        rs.MoveNext
    Next i
    rs.Close
    adoconn.Close
End Sub

Private Sub List1_Click()
    showinfo.Caption = List1.Text
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -