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

📄 stui.vb

📁 我大2做的一个关于面向对象的课程设计
💻 VB
字号:
Imports System.Data
Imports System.Data.OleDb
Public Class stui
    Inherits System.Windows.Forms.Form
    Dim SqlConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=计算机选课系统.mdb"
    Dim Conn As New OleDbConnection(SqlConn)
    Dim DS As New DataSet
    Dim comm As OleDbCommand
#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Ts1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Ts2 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Ts3 As System.Windows.Forms.TextBox
    Friend WithEvents Bs1 As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Label1 = New System.Windows.Forms.Label
        Me.Ts1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Ts2 = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Ts3 = New System.Windows.Forms.TextBox
        Me.Bs1 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.AlternatingBackColor = System.Drawing.Color.OldLace
        Me.DataGrid1.BackColor = System.Drawing.Color.OldLace
        Me.DataGrid1.BackgroundColor = System.Drawing.Color.Tan
        Me.DataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.DataGrid1.CaptionBackColor = System.Drawing.Color.SaddleBrown
        Me.DataGrid1.CaptionForeColor = System.Drawing.Color.OldLace
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.FlatMode = True
        Me.DataGrid1.Font = New System.Drawing.Font("Tahoma", 8.0!)
        Me.DataGrid1.ForeColor = System.Drawing.Color.DarkSlateGray
        Me.DataGrid1.GridLineColor = System.Drawing.Color.Tan
        Me.DataGrid1.HeaderBackColor = System.Drawing.Color.Wheat
        Me.DataGrid1.HeaderFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
        Me.DataGrid1.HeaderForeColor = System.Drawing.Color.SaddleBrown
        Me.DataGrid1.LinkColor = System.Drawing.Color.DarkSlateBlue
        Me.DataGrid1.Location = New System.Drawing.Point(8, 8)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.ParentRowsBackColor = System.Drawing.Color.OldLace
        Me.DataGrid1.ParentRowsForeColor = System.Drawing.Color.DarkSlateGray
        Me.DataGrid1.ReadOnly = True
        Me.DataGrid1.SelectionBackColor = System.Drawing.Color.SlateGray
        Me.DataGrid1.SelectionForeColor = System.Drawing.Color.White
        Me.DataGrid1.Size = New System.Drawing.Size(328, 184)
        Me.DataGrid1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(32, 208)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(32, 23)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "学号"
        '
        'Ts1
        '
        Me.Ts1.Location = New System.Drawing.Point(64, 208)
        Me.Ts1.Name = "Ts1"
        Me.Ts1.TabIndex = 2
        Me.Ts1.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(184, 208)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(32, 23)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "姓名"
        '
        'Ts2
        '
        Me.Ts2.Location = New System.Drawing.Point(224, 208)
        Me.Ts2.Name = "Ts2"
        Me.Ts2.TabIndex = 4
        Me.Ts2.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 248)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(56, 23)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "院系班级"
        '
        'Ts3
        '
        Me.Ts3.Location = New System.Drawing.Point(64, 248)
        Me.Ts3.Name = "Ts3"
        Me.Ts3.TabIndex = 6
        Me.Ts3.Text = ""
        '
        'Bs1
        '
        Me.Bs1.Location = New System.Drawing.Point(32, 280)
        Me.Bs1.Name = "Bs1"
        Me.Bs1.TabIndex = 7
        Me.Bs1.Text = "加入数据库"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(208, 280)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 8
        Me.Button1.Text = "删除学生信息"
        '
        'stui
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(342, 306)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Bs1)
        Me.Controls.Add(Me.Ts3)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Ts2)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Ts1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.DataGrid1)
        Me.MaximizeBox = False
        Me.Name = "stui"
        Me.Text = "stui"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub stui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sqlconns()
    End Sub
    Sub inser()
        Try
            Conn.Open()
            Dim StrSql As String = "Insert into 学生 (学号,姓名,院系班级) values('" & Ts1.Text & "','" & Ts2.Text & "','" & Ts3.Text & "')"
            comm = New OleDbCommand(StrSql, Conn)
            comm.ExecuteNonQuery()
            Conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Conn.Close()
        End Try
    End Sub
    Sub sqlconns()
        DS.Clear()
        Try
            Dim SqlStr As String = "select * from 学生 "
            Dim Comm As New OleDbDataAdapter(SqlStr, Conn)
            Comm.Fill(DS, "学生")
            Conn.Open()
            DataGrid1.DataSource = DS.Tables("学生").DefaultView
            DataGrid1.Refresh()
            Conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Conn.Close()
        End Try
    End Sub

    Private Sub Bs1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bs1.Click
        If Ts1.Text <> "" And Ts2.Text <> "" And Ts3.Text <> "" Then
            inser()
            sqlconns()
            Ts1.Text = ""
            Ts2.Text = ""
            Ts3.Text = ""

        Else
            MessageBox.Show("输入有误,重新输入")
            Ts1.Focus()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        del()
        sqlconns()


    End Sub
    Sub del()
        Try
            Dim Strnum As String
            Strnum = InputBox("请输入要删除的学生号", "删除学生信息")
            If Strnum <> "" Then
                Dim td1 = CDbl(Strnum)
                Conn.Open()
                Dim StrSql As String = "Delete From 学生 Where 学号 = '" & td1 & "'"
                comm = New OleDbCommand(StrSql, Conn)
                comm.ExecuteNonQuery()
                Conn.Close()
                MsgBox("操作完成")
            Else : MsgBox("请输入正确信息")
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Conn.Close()
        End Try
    End Sub
End Class

⌨️ 快捷键说明

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