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.cs
========
Class1 MyDatas = new Class1();
Form1_Load()
{
MyDatas.MyTableFill();
}
Form2.cs
========
Class1 AccDatas=new Class1();
Form2_Load()
{
AccDatas.MyTableFill();
}
Thanks
All you need to to is
a) in your opening form initialize and fill the adapter
b) make a constructor that accepts the adapter in all other forms
c) pass the adapter from one form to the next as a argument
PS: You may also pass the adapter as a reference, that way any changes are saved.
精彩评论