Home All Groups Group Topic Archive Search About

declaring a dataset as public

Author
5 Oct 2006 7:03 PM
Opa Vito
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

Author
5 Oct 2006 7:12 PM
samoore33
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:
Show quoteHide quote
> 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
Author
6 Oct 2006 3:51 AM
Cor Ligthert [MVP]
Vito,

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

Cor

Show quoteHide quote
"Opa Vito" <gebr***@dit.niet> schreef in bericht
news:rLidncTpsaS-yrjYnZ2dnUVZ8qKdnZ2d@scarlet.biz...
> 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
Author
6 Oct 2006 10:08 AM
Phill W.
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.

Show quoteHide quote
>
> Can this be done? How?
>
> Thanks
>
> Vito
Author
6 Oct 2006 12:47 PM
Opa Vito
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