declaring a dataset as public

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Opa Vito

    #1

    declaring a dataset as public

    Hello,

    I can't find out if a DataSet (and/or datatable) can be declared public
    so the xml data can be read to the DataSet in the form load, and then
    can be acessed from whatever sub or function for writing to the xml file
    whitout opening it all the time ...

    Can this be done? How?

    Thanks

    Vito
  • samoore33

    #2
    Re: declaring a dataset as public

    Vito,

    I am not sure I completely understand your question. In one of my
    projects I declare a dataset and datatable as public variables with no
    problem.

    Public myDataSet As New DataSet("State" ) 'creates the dataset
    Public myTable As DataTable 'creates the datatable

    These are global variables that I utilize through out the project. Hope
    this helps.

    Scott Moore

    Opa Vito wrote:
    Hello,
    >
    I can't find out if a DataSet (and/or datatable) can be declared public
    so the xml data can be read to the DataSet in the form load, and then
    can be acessed from whatever sub or function for writing to the xml file
    whitout opening it all the time ...
    >
    Can this be done? How?
    >
    Thanks
    >
    Vito

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: declaring a dataset as public

      Vito,

      I don't see the problem here, can you explain it a little bit more?

      Cor

      "Opa Vito" <gebruik@dit.ni etschreef in bericht
      news:rLidncTpsa S-yrjYnZ2dnUVZ8qK dnZ2d@scarlet.b iz...
      Hello,
      >
      I can't find out if a DataSet (and/or datatable) can be declared public so
      the xml data can be read to the DataSet in the form load, and then can be
      acessed from whatever sub or function for writing to the xml file whitout
      opening it all the time ...
      >
      Can this be done? How?
      >
      Thanks
      >
      Vito

      Comment

      • Phill W.

        #4
        Re: declaring a dataset as public

        Opa Vito wrote:
        I can't find out if a DataSet (and/or datatable) can be declared public
        so the xml data can be read to the DataSet in the form load, and then
        can be acessed from whatever sub or function for writing to the xml file
        whitout opening it all the time ...
        Yes, you can expose a DataSet as a property of your Form so that it can
        be used elsewhere in your Form and/or Project.

        Class Form1

        Private Sub Form_Load( ... ) Handles MyBase.Load
        m_dsData = New DataSet
        m_dsData.Load( ...
        End Sub

        Public ReadOnly Property Data() as DataSet ' or DataTable
        Get
        Return m_dsData
        End Get
        End Property

        End Class

        Then, anywhere within Form1, you can access it as

        ? Me.Data.

        And, from elsewhere in your Project (provided you have a reference to
        the Form1 object),

        ? oFormRef.Data.

        Of course, if you only /have/ the one form, then you can make the Data
        Property private (to the Form) in which case the first example above
        will work, but the second will not.

        HTH,
        Phill W.
        >
        Can this be done? How?
        >
        Thanks
        >
        Vito

        Comment

        • Opa Vito

          #5
          Re: declaring a dataset as public

          Opa Vito schreef:
          I can't find out if a DataSet (and/or datatable) can be declared public
          so the xml data can be read to the DataSet in the form load, and then
          can be acessed from whatever sub or function for writing to the xml file
          whitout opening it all the time ...
          I had problems with the XML file. It got corrupted everytime I had to
          write to it from a certain function, not from all functions. And the
          code seemed OK.
          But I always declared the Dataset and read the XML file into it in all
          functions who had to deal with the dataset, and that was the mistake I
          made (I think).

          Thanks to you I now managed to declare the Dataset public, read the XML
          file into the Dataset at form1 load and the problem is gone. So far I
          can use the Dataset now from everywhere without problems.


          Vito

          Comment

          Working...