📄 frmaddstinfo.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class FrmAddstInfo
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 Label1 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents Label10 As System.Windows.Forms.Label
Friend WithEvents Label11 As System.Windows.Forms.Label
Friend WithEvents Label12 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TxtSID As System.Windows.Forms.TextBox
Friend WithEvents TxtName As System.Windows.Forms.TextBox
Friend WithEvents TxtBornDate As System.Windows.Forms.TextBox
Friend WithEvents TxtTel As System.Windows.Forms.TextBox
Friend WithEvents TxtRuDate As System.Windows.Forms.TextBox
Friend WithEvents TxtComment As System.Windows.Forms.TextBox
Friend WithEvents TxtAddress As System.Windows.Forms.TextBox
Friend WithEvents BtOK As System.Windows.Forms.Button
Friend WithEvents BtCancel As System.Windows.Forms.Button
Friend WithEvents ComboSex As System.Windows.Forms.ComboBox
Friend WithEvents ComboClassno As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label6 = New System.Windows.Forms.Label()
Me.Label8 = New System.Windows.Forms.Label()
Me.Label10 = New System.Windows.Forms.Label()
Me.Label11 = New System.Windows.Forms.Label()
Me.Label12 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.TxtSID = New System.Windows.Forms.TextBox()
Me.TxtName = New System.Windows.Forms.TextBox()
Me.TxtBornDate = New System.Windows.Forms.TextBox()
Me.TxtTel = New System.Windows.Forms.TextBox()
Me.TxtRuDate = New System.Windows.Forms.TextBox()
Me.TxtComment = New System.Windows.Forms.TextBox()
Me.TxtAddress = New System.Windows.Forms.TextBox()
Me.ComboSex = New System.Windows.Forms.ComboBox()
Me.ComboClassno = New System.Windows.Forms.ComboBox()
Me.BtOK = New System.Windows.Forms.Button()
Me.BtCancel = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'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(34, 16)
Me.Label1.TabIndex = 0
Me.Label1.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(16, 142)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(63, 16)
Me.Label4.TabIndex = 3
Me.Label4.Text = "入校时间"
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label6.Location = New System.Drawing.Point(232, 16)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(34, 16)
Me.Label6.TabIndex = 5
Me.Label6.Text = "姓名"
'
'Label8
'
Me.Label8.AutoSize = True
Me.Label8.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label8.Location = New System.Drawing.Point(232, 58)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(63, 16)
Me.Label8.TabIndex = 7
Me.Label8.Text = "出生日期"
'
'Label10
'
Me.Label10.AutoSize = True
Me.Label10.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label10.Location = New System.Drawing.Point(16, 184)
Me.Label10.Name = "Label10"
Me.Label10.Size = New System.Drawing.Size(34, 16)
Me.Label10.TabIndex = 4
Me.Label10.Text = "备注"
'
'Label11
'
Me.Label11.AutoSize = True
Me.Label11.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label11.Location = New System.Drawing.Point(16, 58)
Me.Label11.Name = "Label11"
Me.Label11.Size = New System.Drawing.Size(34, 16)
Me.Label11.TabIndex = 1
Me.Label11.Text = "性别"
'
'Label12
'
Me.Label12.AutoSize = True
Me.Label12.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label12.Location = New System.Drawing.Point(16, 100)
Me.Label12.Name = "Label12"
Me.Label12.Size = New System.Drawing.Size(34, 16)
Me.Label12.TabIndex = 2
Me.Label12.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(232, 100)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(63, 16)
Me.Label3.TabIndex = 6
Me.Label3.Text = "联系电话"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label5.Location = New System.Drawing.Point(232, 142)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(63, 16)
Me.Label5.TabIndex = 8
Me.Label5.Text = "家庭住址"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.TopCenter
'
'TxtSID
'
Me.TxtSID.Location = New System.Drawing.Point(104, 16)
Me.TxtSID.Name = "TxtSID"
Me.TxtSID.Size = New System.Drawing.Size(104, 21)
Me.TxtSID.TabIndex = 9
Me.TxtSID.Text = ""
'
'TxtName
'
Me.TxtName.Location = New System.Drawing.Point(312, 16)
Me.TxtName.Name = "TxtName"
Me.TxtName.Size = New System.Drawing.Size(106, 21)
Me.TxtName.TabIndex = 10
Me.TxtName.Text = ""
'
'TxtBornDate
'
Me.TxtBornDate.Location = New System.Drawing.Point(312, 64)
Me.TxtBornDate.Name = "TxtBornDate"
Me.TxtBornDate.Size = New System.Drawing.Size(106, 21)
Me.TxtBornDate.TabIndex = 11
Me.TxtBornDate.Text = ""
'
'TxtTel
'
Me.TxtTel.Location = New System.Drawing.Point(312, 104)
Me.TxtTel.Name = "TxtTel"
Me.TxtTel.Size = New System.Drawing.Size(106, 21)
Me.TxtTel.TabIndex = 14
Me.TxtTel.Text = ""
'
'TxtRuDate
'
Me.TxtRuDate.Location = New System.Drawing.Point(104, 140)
Me.TxtRuDate.Name = "TxtRuDate"
Me.TxtRuDate.Size = New System.Drawing.Size(104, 21)
Me.TxtRuDate.TabIndex = 15
Me.TxtRuDate.Text = ""
'
'TxtComment
'
Me.TxtComment.Location = New System.Drawing.Point(104, 182)
Me.TxtComment.Name = "TxtComment"
Me.TxtComment.Size = New System.Drawing.Size(104, 21)
Me.TxtComment.TabIndex = 16
Me.TxtComment.Text = ""
'
'TxtAddress
'
Me.TxtAddress.Location = New System.Drawing.Point(312, 144)
Me.TxtAddress.Name = "TxtAddress"
Me.TxtAddress.Size = New System.Drawing.Size(106, 21)
Me.TxtAddress.TabIndex = 17
Me.TxtAddress.Text = ""
'
'ComboSex
'
Me.ComboSex.ItemHeight = 12
Me.ComboSex.Items.AddRange(New Object() {"男", "女"})
Me.ComboSex.Location = New System.Drawing.Point(104, 58)
Me.ComboSex.Name = "ComboSex"
Me.ComboSex.Size = New System.Drawing.Size(104, 20)
Me.ComboSex.TabIndex = 19
'
'ComboClassno
'
Me.ComboClassno.ItemHeight = 12
Me.ComboClassno.Items.AddRange(New Object() {"初一", "初二", "初三", "高一", "高二", "高三"})
Me.ComboClassno.Location = New System.Drawing.Point(104, 99)
Me.ComboClassno.Name = "ComboClassno"
Me.ComboClassno.Size = New System.Drawing.Size(104, 20)
Me.ComboClassno.TabIndex = 20
'
'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(48, 216)
Me.BtOK.Name = "BtOK"
Me.BtOK.Size = New System.Drawing.Size(97, 32)
Me.BtOK.TabIndex = 21
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(288, 216)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(97, 32)
Me.BtCancel.TabIndex = 22
Me.BtCancel.Text = "取消添加"
'
'FrmAddstInfo
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(440, 269)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.BtCancel, Me.BtOK, Me.ComboClassno, Me.ComboSex, Me.TxtAddress, Me.TxtComment, Me.TxtRuDate, Me.TxtTel, Me.TxtBornDate, Me.TxtName, Me.TxtSID, Me.Label8, Me.Label6, Me.Label4, Me.Label1, Me.Label10, Me.Label11, Me.Label12, Me.Label3, Me.Label5})
Me.Name = "FrmAddstInfo"
Me.Text = "添加学籍信息"
Me.TopMost = True
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub BtOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOK.Click
If Not IsNumeric(Trim(TxtSID.Text)) Then
MsgBox("请输入数字!", vbOKOnly + vbExclamation, "警告")
Exit Sub
TxtSID.Focus() '学号必须为数字
End If
If Not IsNumeric(TxtTel.Text) Then
MsgBox("请输入联系电话!", vbOKOnly + vbExclamation, "警告")
TxtTel.Focus() '电话不能为空
Exit Sub
End If
If Not IsDate(TxtRuDate.Text) Then
MsgBox("入校时间应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告")
TxtRuDate.Focus() '入校日期不能为空
End If
Dim tablename As String = "student_Info"
SearchSQL = "select * from student_Info "
ExecuteSQL(SearchSQL, tablename)
Dim newrow As DataRow
newrow = mytable.NewRow
newrow.Item(0) = Trim(TxtSID.Text)
newrow.Item(1) = Trim(TxtName.Text)
newrow.Item(2) = Trim(ComboSex.Text)
newrow.Item(3) = Trim(TxtBornDate.Text)
newrow.Item(4) = Trim(ComboClassno.Text)
newrow.Item(5) = Trim(TxtTel.Text)
newrow.Item(6) = Trim(TxtRuDate.Text)
newrow.Item(7) = Trim(TxtAddress.Text)
newrow.Item(8) = Trim(TxtComment.Text)
mytable.Rows.Add(newrow) '添加新记录
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
Try
ADOcmd.Update(ds, "student_Info")
'对数据库进行更新
MsgBox("添加学籍信息成功!", vbOKOnly + vbExclamation, "警告")
Catch
MsgBox(Err.Description)
End Try
End Sub
Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
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 + -