Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Accessing dataset throughout application.

Accessing dataset throughout application.

Scheduled Pinned Locked Moved C#
questioncsharpwinforms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paper67
    wrote on last edited by
    #1

    I am writing a C# windows forms application. It is a MDI application with lots of seperate forms. They all need to get to tables within a DataSet. What is the best way to make this DataSet "Global" for all forms within the application ? My main thought is to create a static class. Create a static method that returns the dataset. Is this good programming practise ???

    B 1 Reply Last reply
    0
    • P paper67

      I am writing a C# windows forms application. It is a MDI application with lots of seperate forms. They all need to get to tables within a DataSet. What is the best way to make this DataSet "Global" for all forms within the application ? My main thought is to create a static class. Create a static method that returns the dataset. Is this good programming practise ???

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Your application should have a data model somewhere. Ignore the UI for the moment and think about the business logic and the data layer. Typically your main application class (this is often MainForm, though if one is being strict it shouldn't be) will have a reference to a data model – for a simple application this might just be the data set. Any UI views that refer to the data model should then be given a reference to it, possibly via a view-model (or presenter or similar) class if the binding process is more complex than being a direct editor of some part of the data model. Anything more than simple updates should be done with logic in the model layer, which is why you may need to write a class instead of just using a data set. So the short answer is, put it in your main form class or your application class, if you have one, and pass a reference to it to the MDI children when they are created. But I would like you to understand why that is a good idea and how to extend it to more complex view/model situations.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups