declaring a dataset as public

O

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
 
S

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
 
C

Cor Ligthert [MVP]

Vito,

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

Cor
 
P

Phill W.

Opa said:
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.
 
O

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top