?? 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 + -