Stay alive, data! Where to put datasets for global access?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Infog
    New Member
    • Dec 2008
    • 36

    Stay alive, data! Where to put datasets for global access?

    I think I've somehow missed a basic design principle for storing data from databases.

    What is the "correct" way to store data that your whole application needs access to, regardless of which forms are open or which class is reading the data? I would like to store datasets apart from forms, but don't know how to create them in their own space so that they can be referenced in code at design time.

    When I started programming, I was using the AppDomain for everything but realized that it isn't designed for holding a whole database. I use per-table SQL Select statements when I need to load data, am extending my subs to also do per-ID-range SQL Selects for reloading chunks of a table, and the AppDomain doesn't work the way I though it did.

    My other idea is using My.Settings to store datasets, in addition to configuration options. Would that work? I wouldn't want to keep the datasets when closing the program.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    You can use Cache to store your dataset.
    Code:
    DataSet ds;
    //Fill DataSet
    
            Cache["globalDS"] = ds;
    
            DataSet ds1 = Cache["globalDS"] as DataSet;
            //OR
            ds1 = (DataSet)Cache["globalDS"];

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      PRR, that will only work if he is using ASP.NET.

      I'm guessing that you're using VB.NET? You could define the DataSet as a Shared property of the class that loads the data.

      Comment

      • PRR
        Recognized Expert Contributor
        • Dec 2007
        • 750

        #4
        Yes, i assumed the application would be asp.net. Shared/Static DataSet would do the trick... thanks for pointing out :)...

        Comment

        • Infog
          New Member
          • Dec 2008
          • 36

          #5
          Thank you! Yes, I'm using VB.NET.

          Aha! so THAT is what shared means. :) Making my datasets part of a module or shared class should do the trick then.

          Comment

          Working...