what is wrong with this class?
{
private OleDbConnection connection;
public DBInterface(string strcon)
{
connection = new OleDbConnection(strcon);
}
public DBInterface()
{
this.connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\testtab.mdb");
if (true)
{
this.connection.Open();
if (this.connection != null)
Console.Write("Connection State: " + this.connection.State);
else
Console.Write("Connection State: Not Established ");
}
}
~DBInterface()
{
// Destructor logic
}
public void connect()
{
this.connection.Open();
}
public void disconnect()
{
this.connection.Close();
}
public bool getState()
{
if (this.connection != null)
Console.Write("Connection State: " + this.connection.State);
else
Console.Write("Connection State: Not Established Yet");
if (this.connection != null)
{
if (connection.State.Equals("Open"))
return true;
}
return false;
}
the BOLD part says connected , but once you set the true to false and do it this way:
it says it is not connected.
there must be something wrong with the creation of the object 'connection'
DBInterface db = new DBInterface();
// Connnect to database
db.connect();
string str;
if (db.getState())
Console.WriteLine("db is connected");
else
Console.WriteLine("db is not connected");

