📄 frmmodifystinfo.vb
字号:
Me.BtPrev.Text = "上一条记录"
'
'BtLast
'
Me.BtLast.Location = New System.Drawing.Point(336, 16)
Me.BtLast.Name = "BtLast"
Me.BtLast.Size = New System.Drawing.Size(104, 32)
Me.BtLast.TabIndex = 45
Me.BtLast.Text = "最后一条记录"
'
'BtNext
'
Me.BtNext.Location = New System.Drawing.Point(234, 16)
Me.BtNext.Name = "BtNext"
Me.BtNext.Size = New System.Drawing.Size(95, 32)
Me.BtNext.TabIndex = 44
Me.BtNext.Text = "下一条记录"
'
'GroupBox2
'
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.BtModify, Me.BtUpdate, Me.BtDelete, Me.BtCancel})
Me.GroupBox2.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.GroupBox2.Location = New System.Drawing.Point(7, 280)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(439, 56)
Me.GroupBox2.TabIndex = 44
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "修改学籍信息"
'
'BtModify
'
Me.BtModify.Location = New System.Drawing.Point(15, 16)
Me.BtModify.Name = "BtModify"
Me.BtModify.Size = New System.Drawing.Size(95, 32)
Me.BtModify.TabIndex = 46
Me.BtModify.Text = "修改记录"
'
'BtUpdate
'
Me.BtUpdate.Location = New System.Drawing.Point(124, 16)
Me.BtUpdate.Name = "BtUpdate"
Me.BtUpdate.Size = New System.Drawing.Size(95, 32)
Me.BtUpdate.TabIndex = 1
Me.BtUpdate.Text = "更新数据"
'
'BtDelete
'
Me.BtDelete.Location = New System.Drawing.Point(336, 16)
Me.BtDelete.Name = "BtDelete"
Me.BtDelete.Size = New System.Drawing.Size(95, 32)
Me.BtDelete.TabIndex = 45
Me.BtDelete.Text = "删除记录"
'
'BtCancel
'
Me.BtCancel.Location = New System.Drawing.Point(227, 16)
Me.BtCancel.Name = "BtCancel"
Me.BtCancel.Size = New System.Drawing.Size(94, 32)
Me.BtCancel.TabIndex = 44
Me.BtCancel.Text = "取消修改记录"
'
'TxtClassno
'
Me.TxtClassno.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.TxtClassno.Location = New System.Drawing.Point(95, 92)
Me.TxtClassno.Name = "TxtClassno"
Me.TxtClassno.Size = New System.Drawing.Size(117, 21)
Me.TxtClassno.TabIndex = 46
Me.TxtClassno.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(15, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(34, 16)
Me.Label2.TabIndex = 47
Me.Label2.Text = "学号"
'
'ComboSex
'
Me.ComboSex.ItemHeight = 13
Me.ComboSex.Items.AddRange(New Object() {"男", "女"})
Me.ComboSex.Location = New System.Drawing.Point(95, 56)
Me.ComboSex.Name = "ComboSex"
Me.ComboSex.Size = New System.Drawing.Size(117, 21)
Me.ComboSex.TabIndex = 48
'
'FrmModifystInfo
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(464, 349)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ComboSex, Me.Label2, Me.TxtClassno, Me.GroupBox2, Me.GroupBox1, 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 = "FrmModifystInfo"
Me.Text = "修改学籍信息"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub FrmModifystInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
TxtSID.Enabled = False
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False '设置信息为只读
Dim tablename As String = "student_Info"
SearchSQL = "select * from student_Info "
ExecuteSQL(SearchSQL, tablename) '打开数据库
ShowData() '显示记录
End Sub
Private Sub ShowData()
myrow = mytable.Rows.Item(rownumber)
TxtSID.Text = myrow.Item(0).ToString
TxtName.Text = myrow.Item(1).ToString
ComboSex.Text = myrow.Item(2).ToString
TxtBornDate.Text = myrow.Item(3).ToString
TxtClassno.Text = myrow.Item(4).ToString
TxtTel.Text = myrow.Item(5).ToString
TxtRuDate.Text = myrow.Item(6).ToString
TxtAddress.Text = myrow.Item(7).ToString
TxtComment.Text = myrow.Item(8).ToString
End Sub
Private Sub BtFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtFirst.Click
rownumber = 0
ShowData()
End Sub
Private Sub BtPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtPrev.Click
BtNext.Enabled = True
rownumber = rownumber - 1
If rownumber < 0 Then
rownumber = 0 '如果到达记录的首部,行号设为零
BtPrev.Enabled = False
End If
ShowData()
End Sub
Private Sub BtNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtNext.Click
BtPrev.Enabled = True
rownumber = rownumber + 1
If rownumber > mytable.Rows.Count - 1 Then
rownumber = mytable.Rows.Count - 1
BtNext.Enabled = False
End If
ShowData()
End Sub
Private Sub BtLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLast.Click
rownumber = mytable.Rows.Count - 1
ShowData()
End Sub
Private Sub BtDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtDelete.Click
mytable.Rows.Item(rownumber).Delete() '删除记录
If MsgBox("确定要删除改记录吗?", MsgBoxStyle.OKCancel + vbExclamation, "警告") = MsgBoxResult.OK Then
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
ADOcmd.Update(ds, "student_Info")
BtNext.PerformClick()
End If
End Sub
Private Sub BtModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtModify.Click
TxtSID.Enabled = False '关键字段只读
TxtName.Enabled = True '可读写
ComboSex.Enabled = True
TxtBornDate.Enabled = True
TxtClassno.Enabled = True
TxtRuDate.Enabled = True
TxtTel.Enabled = True
TxtAddress.Enabled = True
TxtComment.Enabled = True
End Sub
Private Sub BtUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtUpdate.Click
If Not Testtxt(TxtName.Text) Then
MsgBox("请输入姓名!", vbOKOnly + vbExclamation, "警告")
TxtName.Focus()
Exit Sub
End If
If Not Testtxt(ComboSex.Text) Then
MsgBox("请选择性别!", vbOKOnly + vbExclamation, "警告")
ComboSex.Focus()
Exit Sub
End If
If Not Testtxt(TxtClassno.Text) Then
MsgBox("请选择班号!", vbOKOnly + vbExclamation, "警告")
TxtClassno.Focus()
Exit Sub
End If
If Not Testtxt(TxtTel.Text) Then
MsgBox("请输入联系电话!", vbOKOnly + vbExclamation, "警告")
TxtTel.Focus()
Exit Sub
End If
If Not Testtxt(TxtAddress.Text) Then
MsgBox("请输入家庭住址!", vbOKOnly + vbExclamation, "警告")
TxtAddress.Focus()
Exit Sub
End If
If Not IsNumeric(Trim(TxtSID.Text)) Then
MsgBox("请输入数字学号!", vbOKOnly + vbExclamation, "警告")
Exit Sub
TxtSID.Focus()
End If
If Not IsDate(TxtBornDate.Text) Then
MsgBox("出生时间应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告")
Exit Sub
TxtBornDate.Focus()
End If
If Not IsDate(TxtRuDate.Text) Then
MsgBox("入校时间应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告")
TxtRuDate.Focus()
Exit Sub
End If
myrow.Item(0) = Trim(TxtSID.Text)
myrow.Item(1) = Trim(TxtName.Text)
myrow.Item(2) = Trim(ComboSex.Text)
myrow.Item(3) = Trim(TxtBornDate.Text)
myrow.Item(4) = Trim(TxtClassno.Text)
myrow.Item(5) = Trim(TxtTel.Text)
myrow.Item(6) = Trim(TxtRuDate.Text)
myrow.Item(7) = Trim(TxtAddress.Text)
myrow.Item(8) = Trim(TxtComment.Text)
mytable.GetChanges()
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
ADOcmd.Update(ds, "student_Info")
'对数据库进行更新
MsgBox("修改学籍信息成功!", vbOKOnly + vbExclamation, "警告")
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False '重新设置信息为只读
End Sub
Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
TxtSID.Enabled = False
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False
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 + -