define global var to use throughout vb proj

  • Thread starter Thread starter Steve
  • Start date Start date
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
 
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.
 
Add it to the Application Cache.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
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.
 
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.
 
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)
 
Back
Top