📄 lci.vb
字号:
Imports System.Data
Imports System.Data.OleDb
Public Class lci
Inherits System.Windows.Forms.Form
#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 Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents B1 As System.Windows.Forms.Button
Friend WithEvents Tbx1 As System.Windows.Forms.TextBox
Friend WithEvents Tbx2 As System.Windows.Forms.TextBox
Friend WithEvents Tbx3 As System.Windows.Forms.TextBox
Friend WithEvents Tbx4 As System.Windows.Forms.TextBox
Friend WithEvents B2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.Tbx1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Tbx2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Tbx3 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.Tbx4 = New System.Windows.Forms.TextBox
Me.B1 = New System.Windows.Forms.Button
Me.B2 = 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(0, 0)
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(336, 200)
Me.DataGrid1.TabIndex = 0
'
'Tbx1
'
Me.Tbx1.Location = New System.Drawing.Point(64, 208)
Me.Tbx1.Name = "Tbx1"
Me.Tbx1.TabIndex = 1
Me.Tbx1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 208)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 23)
Me.Label1.TabIndex = 2
Me.Label1.Text = "课程号"
'
'Tbx2
'
Me.Tbx2.Location = New System.Drawing.Point(232, 208)
Me.Tbx2.Name = "Tbx2"
Me.Tbx2.TabIndex = 3
Me.Tbx2.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(176, 208)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 23)
Me.Label2.TabIndex = 4
Me.Label2.Text = "课程名称"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(0, 240)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 23)
Me.Label3.TabIndex = 5
Me.Label3.Text = "任课老师"
'
'Tbx3
'
Me.Tbx3.Location = New System.Drawing.Point(64, 240)
Me.Tbx3.Name = "Tbx3"
Me.Tbx3.TabIndex = 6
Me.Tbx3.Text = ""
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(200, 240)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(32, 23)
Me.Label4.TabIndex = 7
Me.Label4.Text = "学分"
'
'Tbx4
'
Me.Tbx4.Location = New System.Drawing.Point(232, 240)
Me.Tbx4.Name = "Tbx4"
Me.Tbx4.TabIndex = 8
Me.Tbx4.Text = ""
'
'B1
'
Me.B1.Location = New System.Drawing.Point(40, 272)
Me.B1.Name = "B1"
Me.B1.TabIndex = 9
Me.B1.Text = "加入数据库"
'
'B2
'
Me.B2.Location = New System.Drawing.Point(200, 272)
Me.B2.Name = "B2"
Me.B2.TabIndex = 10
Me.B2.Text = "删除信息"
'
'lci
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(342, 306)
Me.Controls.Add(Me.B2)
Me.Controls.Add(Me.B1)
Me.Controls.Add(Me.Tbx4)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Tbx3)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Tbx2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Tbx1)
Me.Controls.Add(Me.DataGrid1)
Me.MaximizeBox = False
Me.Name = "lci"
Me.Text = "lci"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
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
Private Sub lci_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('" & Tbx1.Text & "','" & Tbx2.Text & "','" & Tbx3.Text & "','" & Tbx4.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 del()
Try
Dim Strnum As String
Strnum = InputBox("请输入要删除的课程号称", "删除课程")
Dim td1 = CDbl(Strnum)
If Strnum <> "" Then
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
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 B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
If Tbx1.Text <> "" And Tbx2.Text <> "" And Tbx3.Text <> "" And Tbx4.Text <> "" Then
inser()
sqlconns()
Tbx1.Text = ""
Tbx2.Text = ""
Tbx3.Text = ""
Tbx4.Text = ""
MsgBox("完成")
Else
MessageBox.Show("输入有误,重新输入")
Tbx1.Focus()
End If
End Sub
Private Sub B2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
del()
sqlconns()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -