📄 frmresult.vb
字号:
Imports System.Data
Imports System.Data.OleDb
Public Class frmResult
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 lblNumber As System.Windows.Forms.Label
Friend WithEvents lblName As System.Windows.Forms.Label
Friend WithEvents lblClass As System.Windows.Forms.Label
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents b1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblNumber = New System.Windows.Forms.Label
Me.lblName = New System.Windows.Forms.Label
Me.lblClass = New System.Windows.Forms.Label
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.b1 = New System.Windows.Forms.Button
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'lblNumber
'
Me.lblNumber.Location = New System.Drawing.Point(40, 24)
Me.lblNumber.Name = "lblNumber"
Me.lblNumber.Size = New System.Drawing.Size(80, 23)
Me.lblNumber.TabIndex = 0
'
'lblName
'
Me.lblName.Location = New System.Drawing.Point(136, 24)
Me.lblName.Name = "lblName"
Me.lblName.Size = New System.Drawing.Size(64, 23)
Me.lblName.TabIndex = 1
'
'lblClass
'
Me.lblClass.Location = New System.Drawing.Point(216, 24)
Me.lblClass.Name = "lblClass"
Me.lblClass.Size = New System.Drawing.Size(152, 23)
Me.lblClass.TabIndex = 2
'
'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(16, 64)
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, 184)
Me.DataGrid1.TabIndex = 5
'
'b1
'
Me.b1.Location = New System.Drawing.Point(136, 272)
Me.b1.Name = "b1"
Me.b1.Size = New System.Drawing.Size(88, 23)
Me.b1.TabIndex = 6
Me.b1.Text = "删除已选课程"
'
'frmResult
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(368, 306)
Me.Controls.Add(Me.b1)
Me.Controls.Add(Me.DataGrid1)
Me.Controls.Add(Me.lblClass)
Me.Controls.Add(Me.lblName)
Me.Controls.Add(Me.lblNumber)
Me.MaximizeBox = False
Me.Name = "frmResult"
Me.Text = "frmResult"
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
Public Sub updatenow()
Try
ds.Clear()
Dim sql1 As String = frmLogin.strStrdentNumber
Dim sql2 As String = " select 课程号 from 选课表 where 学号 ='" & sql1 & "'"
Dim sql As String = "select * from 课程 where 课程号 in(" & "" & sql2 & ")"
Dim com As New OleDbCommand(sql)
Dim Comm As New OleDbDataAdapter(sql, Conn)
Comm.Fill(ds, "课程")
Conn.Open()
DataGrid1.DataSource = ds.Tables("课程").DefaultView
DataGrid1.Refresh()
Conn.Close()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "出错")
Exit Try
End Try
End Sub
Private Sub frmResult_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblNumber.Text &= frmLogin.strStrdentNumber
lblName.Text &= frmLogin.strStrdentName
lblClass.Text &= frmLogin.strStrdentClass
updatenow()
End Sub
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim curriculumform As New frmCurriculum
curriculumform.ShowDialog(Me)
End Sub
Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
del()
updatenow()
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 + -