vb.net mdi应用程序共享数据集

时间:2014-09-16 18:01:29

标签: vb.net dataset shared mdi

我有一个VB.net MDI应用程序,子窗体使用数据集和单个表。十几个孩子意味着十几个数据集。现在我想比较数据,追加和合并表。移动到具有12个表的单个共享数据集将是最方便的。到目前为止,我还没有成功编写智能感知会接受的共享数据集。任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

在应用程序中创建一个包含数据集的模块,并让子表单与之交互。在这里,我能够在intellisense中看到数据集。

Module Module1
    Private _sharedData As DataSet
    Public Property SharedData As DataSet
        Get
            If (Module1._sharedData Is Nothing) Then
                Module1._sharedData = New DataSet()
            End If
            Return Module1._sharedData
        End Get
        Set(value As DataSet)
            Module1._sharedData = value
        End Set
    End Property

End Module

让您的子表单在数据集中管理自己的表。

Public Class ChildForm

    Public Sub New(ByVal Name As String)
        Me.InitializeComponent()
        Me.Name = Name
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Module1.SharedData.Tables.Add("MyTable" + Me.Name)
    End Sub

End Class

这是来自MDI家长的测试。

Public Class Form1

    Private Shared NextNumber As Integer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim addFrm = New ChildForm(NextNumber.ToString)

        addFrm.MdiParent = Me
        addFrm.Show()

        NextNumber = NextNumber + 1

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MessageBox.Show(Module1.SharedData.Tables.Count)
    End Sub
End Class