📄 frmaddclassinfo.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class FrmAddClassInfo
Inherits System.Windows.Forms.Form
Public ADOcmd As OleDbDataAdapter
Public ds As DataSet = New DataSet()
'建立DataSet对象
Public mytable As Data.DataTable
'建立表单对象
Public myrow As Data.DataRow
'建立数据行对象
Public rownumber As Integer
'定义一个整型变量来存放当前行数
Public SearchSQL As String
Public cmd As OleDbCommandBuilder
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
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 TxtClassno As System.Windows.Forms.TextBox
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 BtOK As System.Windows.Forms.Button
Friend WithEvents BtCancel As System.Windows.Forms.Button
Friend WithEvents TxtInspector As System.Windows.Forms.TextBox
Friend WithEvents TxtClassroom As System.Windows.Forms.TextBox
Friend WithEvents ComboGrade As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TxtClassno = New System.Windows.Forms.TextBox()
Me.TxtInspector = New System.Windows.Forms.TextBox()
Me.TxtClassroom = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.BtOK = New System.Windows.Forms.Button()
Me.BtCancel = New System.Windows.Forms.Button()
Me.ComboGrade = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'TxtClassno
'
Me.TxtClassno.Location = New System.Drawing.Point(80, 16)
Me.TxtClassno.Name = "TxtClassno"
Me.TxtClassno.Size = New System.Drawing.Size(64, 21)
Me.TxtClassno.TabIndex = 0
Me.TxtClassno.Text = ""
'
'TxtInspector
'
Me.TxtInspector.Location = New System.Drawing.Point(80, 56)
Me.TxtInspector.Name = "TxtInspector"
Me.TxtInspector.Size = New System.Drawing.Size(64, 21)
Me.TxtInspector.TabIndex = 1
Me.TxtInspector.Text = ""
'
'TxtClassroom
'
Me.TxtClassroom.Location = New System.Drawing.Point(216, 64)
Me.TxtClassroom.Name = "TxtClassroom"
Me.TxtClassroom.Size = New System.Drawing.Size(80, 21)
Me.TxtClassroom.TabIndex = 2
Me.TxtClassroom.Text = ""
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(49, 16)
Me.Label1.TabIndex = 3
Me.Label1.Text = "班号:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.Location = New System.Drawing.Point(152, 16)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(49, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "年级:"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label3.Location = New System.Drawing.Point(16, 56)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(63, 16)
Me.Label3.TabIndex = 5
Me.Label3.Text = "班主任:"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label4.Location = New System.Drawing.Point(152, 64)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(49, 16)
Me.Label4.TabIndex = 6
Me.Label4.Text = "教室:"
'
'BtOK
'
Me.BtOK.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.BtOK.Location = New System.Drawing.Point(40, 96)
Me.BtOK.Name = "BtOK"
Me.BtOK.Size = New System.Drawing.Size(88, 32)
Me.BtOK.TabIndex = 7
Me.BtOK.Text = "确认添加"
'
'BtCancel
'
Me.BtCancel.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.BtCancel.Location = New System.Drawing.Point(192, 96)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(88, 32)
Me.BtCancel.TabIndex = 8
Me.BtCancel.Text = "取消添加"
'
'ComboGrade
'
Me.ComboGrade.Items.AddRange(New Object() {"初一", "初二", "初三", "高一", "高二", "高三"})
Me.ComboGrade.Location = New System.Drawing.Point(216, 16)
Me.ComboGrade.Name = "ComboGrade"
Me.ComboGrade.Size = New System.Drawing.Size(80, 20)
Me.ComboGrade.TabIndex = 9
'
'FrmAddClassInfo
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(312, 141)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ComboGrade, Me.BtCancel, Me.BtOK, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.TxtClassroom, Me.TxtInspector, Me.TxtClassno})
Me.Name = "FrmAddClassInfo"
Me.Text = "添加班级信息"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
Me.Dispose()
End Sub
Private Sub FrmAddClassInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
SearchSQL = "select * from Class_Info "
ADOcmd = New OleDbDataAdapter(SearchSQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\冯军\student.mdb")
ADOcmd.Fill(ds, "Class_Info")
mytable = ds.Tables.Item(0)
Dim i As Integer
For i = 0 To mytable.Rows.Count - 1
myrow = mytable.Rows.Item(i)
If TxtClassno.Text = myrow.Item(0).ToString Then
MsgBox("学号重复,请重新输入!", vbOKOnly + vbExclamation, "警告")
Exit Sub
End If
Next
Dim newrow As DataRow
newrow = mytable.NewRow
newrow.Item(0) = Trim(TxtClassno.Text)
newrow.Item(1) = Trim(ComboGrade.Text)
newrow.Item(2) = Trim(TxtInspector.Text)
newrow.Item(3) = Trim(TxtClassroom.Text)
'SearchSQL = "select * from student_Info "
'ADOcmd = New OleDbDataAdapter(SearchSQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb")
'ADOcmd.Fill(ds, "student_Info")
mytable.Rows.Add(newrow)
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
ADOcmd.Update(ds, "Class_Info")
'对数据库进行更新
MsgBox("添加班级信息成功!", vbOKOnly + vbExclamation, "警告")
Me.Dispose()
End Sub
Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)
Try
'建立ADODataSetCommand对象
'数据库查询函数
ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\冯军\student.mdb")
'建立ADODataSetCommand对象
ADOcmd.Fill(ds, table) '取得表单
mytable = ds.Tables.Item(0) '取得名为table的表
rownumber = 0 '设置为第一行
myrow = mytable.Rows.Item(rownumber)
'取得第一行数据
Catch
MsgBox(Err.Description)
End Try
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -