Results 1 to 4 of 4

Thread: populated dataset available throughout the application

  1. #1

    Thread Starter
    Lively Member kyrsoronas's Avatar
    Join Date
    Jun 2012
    Location
    Mordor
    Posts
    89

    Question populated dataset available throughout the application

    Hello fellow coders. I'm having the following issue. I have populated a dataset at the form load event of a form in my application. I want the data in the dataset to be available throughout the application until i close it. How can I do that ? Also is there a way besides global variables to do so ? thank you in advance.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,548

    Re: populated dataset available throughout the application

    Two ways come to mind. Create Public dataset/dataadapter/datatables in a module. They will be available throughout the app. Or, after you've created your dataset, pass the data to the different forms or functions or subs in your app.

    It really depends on the app.

  3. #3

    Thread Starter
    Lively Member kyrsoronas's Avatar
    Join Date
    Jun 2012
    Location
    Mordor
    Posts
    89

    Re: populated dataset available throughout the application

    I'm trying to keep my variables local....so in order to pass the data to a different fkrm do i have to create an object reference ?

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,548

    Re: populated dataset available throughout the application

    There's more than one way here's a simple example.
    Code:
    Imports System.Data.OleDb
    Public Class Form6
    
        Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
    
            Try
                Dim con As New OleDbConnection(My.Settings.WaterDbConnectionString)
                con.Open()
                Dim ds As New DataSet
                Dim da As New OleDb.OleDbDataAdapter("select tagnumber from tags", con)
                Dim dt As New DataTable
                ds.Tables.Add(dt)
                da.Fill(ds, "dt")
    
                Dim frm As New Form4(ds)
                frm.Show()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    
    End Class
    This example sends a dataset to From4

    Code:
    Imports System.Data.OleDb
    Public Class Form4
        Private ds As New DataSet
        Public Sub New(ByVal dsParam As DataSet)
            ' This call is required by the designer.
            InitializeComponent()
            ds = dsParam
        End Sub
    
        Private Sub Form4_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
    
    
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            MessageBox.Show(ds.Tables("dt").Rows.Count.ToString)
    
        End Sub
    End Class
    Try Googling something like ".net passing data between forms"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width