How to keep data available for whole project access?
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
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"
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
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
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
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.
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
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
-
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.csClass1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.csClass1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}Thanks:thumbsup:
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.