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. How to keep data available for whole project access?

How to keep data available for whole project access?

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
6 Posts 6 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
    Paramu1973
    wrote on last edited by
    #1

    Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

    Class1.cs

    public void MyTableFill()
    {
    Con.ConnectionString = Con_1;
    Con.Open();
    SQLDAp = new SqlDataAdapter(MyQry, Con);
    SQLDAp.Fill(MyTable);
    Con.Close();
    }
    Form1.cs

    Class1 MyDatas = new Class1();
    Form1_Load()
    {
    MyDatas.MyTableFill();
    }
    Form2.cs

    Class1 AccDatas=new Class1();
    Form2_Load()
    {
    AccDatas.MyTableFill();
    }

    Thanks:thumbsup:

    B M P Y M 5 Replies Last reply
    0
    • P Paramu1973

      Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

      Class1.cs

      public void MyTableFill()
      {
      Con.ConnectionString = Con_1;
      Con.Open();
      SQLDAp = new SqlDataAdapter(MyQry, Con);
      SQLDAp.Fill(MyTable);
      Con.Close();
      }
      Form1.cs

      Class1 MyDatas = new Class1();
      Form1_Load()
      {
      MyDatas.MyTableFill();
      }
      Form2.cs

      Class1 AccDatas=new Class1();
      Form2_Load()
      {
      AccDatas.MyTableFill();
      }

      Thanks:thumbsup:

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

      This type of question is among the most frequently asked and answered questions on the Q/A forums here: Check out: Passing Data Between Forms[^] How to display information entered on one form to another form without database connectivity?[^] Pass value between two form in vb.net[^]

      "Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"

      1 Reply Last reply
      0
      • P Paramu1973

        Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

        Class1.cs

        public void MyTableFill()
        {
        Con.ConnectionString = Con_1;
        Con.Open();
        SQLDAp = new SqlDataAdapter(MyQry, Con);
        SQLDAp.Fill(MyTable);
        Con.Close();
        }
        Form1.cs

        Class1 MyDatas = new Class1();
        Form1_Load()
        {
        MyDatas.MyTableFill();
        }
        Form2.cs

        Class1 AccDatas=new Class1();
        Form2_Load()
        {
        AccDatas.MyTableFill();
        }

        Thanks:thumbsup:

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I keep a static class that hold all the lists that support dimension data (typically stuff for comboboxes), every form uses this for static data. When the get accessor is called it checks for content and if there is none it gets the data from the database. If the app changes the static data then the list is set to null. Next time it is requested the data is refreshed from the database. This does not work well for asynch processing (Silverlight);

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • P Paramu1973

          Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

          Class1.cs

          public void MyTableFill()
          {
          Con.ConnectionString = Con_1;
          Con.Open();
          SQLDAp = new SqlDataAdapter(MyQry, Con);
          SQLDAp.Fill(MyTable);
          Con.Close();
          }
          Form1.cs

          Class1 MyDatas = new Class1();
          Form1_Load()
          {
          MyDatas.MyTableFill();
          }
          Form2.cs

          Class1 AccDatas=new Class1();
          Form2_Load()
          {
          AccDatas.MyTableFill();
          }

          Thanks:thumbsup:

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          The data access should not be in the UI layer at all. Have a separate class that encapsulates the data access and pass a reference to an instance of it to each form.

          1 Reply Last reply
          0
          • P Paramu1973

            Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

            Class1.cs

            public void MyTableFill()
            {
            Con.ConnectionString = Con_1;
            Con.Open();
            SQLDAp = new SqlDataAdapter(MyQry, Con);
            SQLDAp.Fill(MyTable);
            Con.Close();
            }
            Form1.cs

            Class1 MyDatas = new Class1();
            Form1_Load()
            {
            MyDatas.MyTableFill();
            }
            Form2.cs

            Class1 AccDatas=new Class1();
            Form2_Load()
            {
            AccDatas.MyTableFill();
            }

            Thanks:thumbsup:

            Y Offline
            Y Offline
            Yasser Sobhy
            wrote on last edited by
            #5

            the best way is to create a global class and retrieve information from the database and store it in that class, and when any form needs that data it reads it from the global class

            1 Reply Last reply
            0
            • P Paramu1973

              Well. I have done a small project. But the problem is some of my required data is not available across whole project. I mean, every time I go form to form I need to open the database and fill the same data from the same SqlDataAdapter. Instead is it possible to keep the data somewhere globally for all the project forms? With my project I have a class for the queries and tables and wherever I need data in the forms, there I use to call the Subs for filling the table like the below...

              Class1.cs

              public void MyTableFill()
              {
              Con.ConnectionString = Con_1;
              Con.Open();
              SQLDAp = new SqlDataAdapter(MyQry, Con);
              SQLDAp.Fill(MyTable);
              Con.Close();
              }
              Form1.cs

              Class1 MyDatas = new Class1();
              Form1_Load()
              {
              MyDatas.MyTableFill();
              }
              Form2.cs

              Class1 AccDatas=new Class1();
              Form2_Load()
              {
              AccDatas.MyTableFill();
              }

              Thanks:thumbsup:

              M Offline
              M Offline
              Muhammad Shahid Farooq
              wrote on last edited by
              #6

              Use layered approach (tier). In your case three tier approach is suitable: DAL–Data Access Layer, BLL–Business Logic Layer and GUI –Graphical User Interface.

              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