DataGrid.Datasource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a class for DatabaseManager.cs that has all the connection path, add,
update, delete.I have a problem with the datagrid because I have a form that
contains the datagrid called frmAllProjects.cs, so how do I connected to my
dbmanager.cs from the form.
DatabaseManager Code:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";
Conn.ConnectionString = sConnString;
Conn.Open();

string select = "select * from Project";
OleDbDataAdapter da = new OleDbDataAdapter (select, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
frmAllProjects code: <-- this is the form Code
DatabaseManager manager = new DatabaseManager();
manager.path();
//Datagrid
dg1.Datasource = ds (); <-- I get the error here because ds is not found --
But when I have all the code on the datagrid it works fine.

Also I do not what th hardcode the data Source like this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";

I want to do this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Project.mdb"; <-- it does not work like this
 
Hi Freddy,

The simplest solution would probably be to have the DatabaseManager class
keep a reference to the retrieved dataset and return the reference as a
read-only public property.
Obviously the form containing the grid must keep a reference to the
DatabaseManager instance during the form's lifetime.
 
Back
Top