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

📄 删除成绩.frm

📁 初学vb,做的第一个系统.一个星期内看vb并做完这个系统的.
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form gra_del 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "删除成绩"
   ClientHeight    =   3060
   ClientLeft      =   5040
   ClientTop       =   4485
   ClientWidth     =   5340
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3060
   ScaleWidth      =   5340
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   240
      Top             =   2760
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   661
      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.CommandButton Command2 
      Caption         =   "删除"
      Height          =   495
      Left            =   3360
      TabIndex        =   9
      Top             =   2160
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "删除"
      Height          =   495
      Left            =   720
      TabIndex        =   8
      Top             =   2160
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   1080
      Width           =   1455
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   1080
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   1080
      Width           =   1215
   End
   Begin VB.Label Label5 
      Caption         =   "学号"
      Height          =   255
      Left            =   3000
      TabIndex        =   6
      Top             =   1200
      Width           =   495
   End
   Begin VB.Label Label4 
      Caption         =   "删除某学生的所有成绩"
      Height          =   255
      Left            =   3120
      TabIndex        =   5
      Top             =   360
      Width           =   1935
   End
   Begin VB.Label Label3 
      Caption         =   "删除某科目的所有成绩"
      Height          =   255
      Left            =   360
      TabIndex        =   4
      Top             =   360
      Width           =   2175
   End
   Begin VB.Label sub_name 
      Height          =   255
      Left            =   1080
      TabIndex        =   3
      Top             =   1560
      Width           =   1455
   End
   Begin VB.Label Label2 
      Caption         =   "课程名称"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   1560
      Width           =   735
   End
   Begin VB.Label Label1 
      Caption         =   "课程编号"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   1080
      Width           =   735
   End
   Begin VB.Line Line1 
      X1              =   2640
      X2              =   2640
      Y1              =   240
      Y2              =   2760
   End
End
Attribute VB_Name = "gra_del"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
    Public sub_id As String
    Public stu_no As String
    Public rs As New ADODB.Recordset
    Public adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。

Private Sub Combo1_Click()
    sub_id = Combo1.Text
    adoconn.Open
    rs.Open "select * from subject where id='" & sub_id & "'", adoconn
    If rs.RecordCount = 0 Then
        MsgBox "没有该课程!"
        rs.Close
        adoconn.Close
        Exit Sub
    End If
    If sub_id = rs.Fields("id") Then
        sub_name = rs.Fields("name")
        rs.Close
        adoconn.Close
    End If
End Sub

Private Sub Command1_Click()
    If Len(Combo1.Text) = 0 Then
        MsgBox "请选择要删除的科目!"
        Combo1.SetFocus
        Exit Sub
    End If
    Dim r As Integer
    r = MsgBox("你确定要删除该科目所有成绩吗?", 4 + 32 + 0, "确认删除")
    If r = 6 Then
        adoconn.Open
        rs.Open "delete from grade where sub_id='" & sub_id & "'", adoconn
        adoconn.Close
        MsgBox "删除成功!"
        Combo1.SetFocus
        sub_name.Caption = ""
        Call load
    End If
End Sub

Private Sub Command2_Click()
    stu_no = Text1.Text
    If Len(stu_no) = 0 Then
        MsgBox "请输入学号!"
        Text1.SetFocus
        Exit Sub
    End If
    
    Dim r As Integer
    r = MsgBox("你确定要删除该生的所有成绩吗?", 4 + 32 + 0, "确认删除")
    If r = 6 Then
        adoconn.Open
        rs.Open "select * from grade where stu_no='" & stu_no & "'", adoconn
        If rs.RecordCount = 0 Then
            MsgBox "数据库中没有该学生的任何成绩!"
            rs.Close
            adoconn.Close
            Exit Sub
        Else
            rs.Close
            rs.Open "delete from grade where stu_no='" & stu_no & "'", adoconn
            adoconn.Close
            MsgBox "删除成功!"
            Text1.Text = ""
            Text1.SetFocus
        End If
    End If
End Sub

Private Sub Form_Load()
    Call load
End Sub

Private Sub load()
    Combo1.clear
    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 subject", adoconn
    If rs.RecordCount = 0 Then
        rs.Close
        adoconn.Close
        Exit Sub
    End If
    
    Dim i As Integer
    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 + -