⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataform1.vb

📁 Visual Basic .NET程序设计教程源代码
💻 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 objDataSet1 As WindowsApplication1.DataSet1
    Friend WithEvents btnLoad As System.Windows.Forms.Button
    Friend WithEvents grddetail As System.Windows.Forms.DataGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.objDataSet1 = New WindowsApplication1.DataSet1
        Me.btnLoad = New System.Windows.Forms.Button
        Me.grddetail = New System.Windows.Forms.DataGrid
        CType(Me.objDataSet1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.grddetail, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'objDataSet1
        '
        Me.objDataSet1.DataSetName = "DataSet1"
        Me.objDataSet1.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)"
        '
        'grddetail
        '
        Me.grddetail.DataMember = "detail"
        Me.grddetail.DataSource = Me.objDataSet1
        Me.grddetail.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.grddetail.Location = New System.Drawing.Point(10, 43)
        Me.grddetail.Name = "grddetail"
        Me.grddetail.Size = New System.Drawing.Size(380, 197)
        Me.grddetail.TabIndex = 1
        '
        'DataForm1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(392, 223)
        Me.Controls.Add(Me.btnLoad)
        Me.Controls.Add(Me.grddetail)
        Me.Name = "DataForm1"
        Me.Text = "DataForm1"
        CType(Me.objDataSet1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.grddetail, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    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
    Public Sub LoadDataSet()
        '创建一个新数据集以保存从 FillDataSet 调用返回的记录。
        '使用了一个临时数据集,这是因为填充现有的数据集
        '需要重新绑定数据绑定。
        Dim objDataSetTemp As WindowsApplication1.DataSet1
        objDataSetTemp = New WindowsApplication1.DataSet1
        Try
            '尝试填充临时数据集。
            objDataSetTemp = CType(Me.objDataSet1.Clone, WindowsApplication1.DataSet1)
        Catch eFillDataSet As System.Exception
            '在此处添加错误处理代码。
            Throw eFillDataSet
        End Try
        Try
            grddetail.DataSource = Nothing
            '清空数据集中的旧记录。
            objDataSet1.Clear()
            '将记录合并到主数据集中。
            objDataSet1.Merge(objDataSetTemp)
            grddetail.SetDataBinding(objDataSet1, "detail")
        Catch eLoadMerge As System.Exception
            '在此处添加错误处理代码。
            Throw eLoadMerge
        End Try

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -