📄 dataform1.vb
字号:
Public Class DataForm1
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 objds1 As WindowsApplication1.ds1
Friend WithEvents btnLoad As System.Windows.Forms.Button
Friend WithEvents btnUpdate As System.Windows.Forms.Button
Friend WithEvents btnCancelAll As System.Windows.Forms.Button
Friend WithEvents grd工资表 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.objds1 = New WindowsApplication1.ds1
Me.btnLoad = New System.Windows.Forms.Button
Me.btnUpdate = New System.Windows.Forms.Button
Me.btnCancelAll = New System.Windows.Forms.Button
Me.grd工资表 = New System.Windows.Forms.DataGrid
CType(Me.objds1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.grd工资表, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'objds1
'
Me.objds1.DataSetName = "ds1"
Me.objds1.Locale = New System.Globalization.CultureInfo("zh-CN")
'
'btnLoad
'
Me.btnLoad.Location = New System.Drawing.Point(10, 10)
Me.btnLoad.Name = "btnLoad"
Me.btnLoad.Size = New System.Drawing.Size(88, 23)
Me.btnLoad.TabIndex = 0
Me.btnLoad.Text = "加载(&L)"
'
'btnUpdate
'
Me.btnUpdate.Location = New System.Drawing.Point(302, 10)
Me.btnUpdate.Name = "btnUpdate"
Me.btnUpdate.Size = New System.Drawing.Size(88, 23)
Me.btnUpdate.TabIndex = 1
Me.btnUpdate.Text = "更新(&U)"
'
'btnCancelAll
'
Me.btnCancelAll.Location = New System.Drawing.Point(302, 43)
Me.btnCancelAll.Name = "btnCancelAll"
Me.btnCancelAll.Size = New System.Drawing.Size(88, 23)
Me.btnCancelAll.TabIndex = 2
Me.btnCancelAll.Text = "全部取消(&N)"
'
'grd工资表
'
Me.grd工资表.DataMember = "工资表"
Me.grd工资表.DataSource = Me.objds1
Me.grd工资表.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grd工资表.Location = New System.Drawing.Point(10, 76)
Me.grd工资表.Name = "grd工资表"
Me.grd工资表.Size = New System.Drawing.Size(438, 220)
Me.grd工资表.TabIndex = 3
'
'DataForm1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(480, 325)
Me.Controls.Add(Me.btnLoad)
Me.Controls.Add(Me.btnUpdate)
Me.Controls.Add(Me.btnCancelAll)
Me.Controls.Add(Me.grd工资表)
Me.Name = "DataForm1"
Me.Text = "DataForm1"
CType(Me.objds1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.grd工资表, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Try
'尝试更新数据源。
Me.UpdateDataSet()
Catch eUpdate As System.Exception
'在此处添加错误处理代码。
'显示错误信息(如果有)。
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
End Try
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Try
'尝试加载数据集。
Me.LoadDataSet()
Catch eLoad As System.Exception
'在此处添加错误处理代码。
'显示错误信息(如果有)。
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End Try
End Sub
Private Sub btnCancelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelAll.Click
Me.objds1.RejectChanges()
End Sub
Public Sub UpdateDataSet()
'创建一个新数据集来保存对主数据集所做的更改。
Dim objDataSetChanges As WindowsApplication1.ds1 = New WindowsApplication1.ds1
Dim objDataSetUpdated As System.Data.DataSet = New WindowsApplication1.ds1
'停止当前的任何编辑。
Me.BindingContext(objds1, "工资表").EndCurrentEdit()
'获取对主数据集所做的更改。
objDataSetChanges = CType(objds1.GetChanges, WindowsApplication1.ds1)
'检查是否做了任何更改。
If (Not (objDataSetChanges) Is Nothing) Then
Try
'需要做一些更改,所以尝试通过调用 update 方法
'和传递数据集以及任何参数来更新数据源。
objDataSetUpdated = Me.objds1.Clone
Catch eUpdate As System.Exception
'在此处添加错误处理代码。
Throw eUpdate
End Try
'添加代码以检查返回的数据集中是否有任何可能已被
'推入到行对象错误中的错误。
Try
objds1.Merge(objDataSetUpdated)
Catch eUpdateMerge As System.Exception
'在此处添加异常处理代码
Throw eUpdateMerge
End Try
'提交刚刚合并的更改
'这将会改动任何标记为已更新、已插入或已更改的行,将其标记为原始值
objds1.AcceptChanges()
End If
End Sub
Public Sub LoadDataSet()
'创建一个新数据集以保存从 FillDataSet 调用返回的记录。
'使用了一个临时数据集,这是因为填充现有的数据集
'需要重新绑定数据绑定。
Dim objDataSetTemp As WindowsApplication1.ds1
objDataSetTemp = New WindowsApplication1.ds1
Try
'尝试填充临时数据集。
objDataSetTemp = CType(Me.objds1.Clone, WindowsApplication1.ds1)
Catch eFillDataSet As System.Exception
'在此处添加错误处理代码。
Throw eFillDataSet
End Try
Try
grd工资表.DataSource = Nothing
'清空数据集中的旧记录。
objds1.Clear()
'将记录合并到主数据集中。
objds1.Merge(objDataSetTemp)
grd工资表.SetDataBinding(objds1, "工资表")
Catch eLoadMerge As System.Exception
'在此处添加错误处理代码。
Throw eLoadMerge
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -