define global var to use throughout vb proj

S

Steve

I would like to define a datatable object globally so that
I don't have to keep reconnecting to a datasource and thus
use this object variable throughout my vb project on
different aspx pages. Is this possible? I tried defining
a global datatable var in Public Class Global
(Global.asax.vb)

Public Class Global
Public DT As DataTabl
....
but when I tried to reference this in an aspx page I did
not get anything

Dim t1 As ...nothing

Is it possible to create global objects like this? Is
this done at Global.asax.vb?

Thanks
 
S

Steve

Well, I tried passing my datatable in the session object,
and that seems to work (for now) since my table is pretty
small. Some how, I am guessing this would not be the best
practice. Any suggestions welcome.
 
K

Kevin Spencer

Add it to the Application Cache.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
K

Kevin Spencer

Putting it in a Session variable creates a copy for each user. Put it in the
Application Cache.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
S

Steve

Thanks. That is exactly what I was looking for. I just
couldn't connect my brain for some reason. Works
perfectly! Many thanks for your suggestion.
 
B

bruce barker

if you want to share it across all pages, just declare it shared.

Public Class Global
Public Shared DT As DataTable '* only one instance exits
End Class


note: DataTables are only thread safe for reading, you need to sync/lock for
updates.

-- bruce (sqlwork.com)
 

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