public abstract class DBFactory
{
public abstract IDbConnection GetDBConnection();
public abstract IDbCommand GetDBCommand();
public abstract IDbDataAdapter GetDataAdapter(IDbCommand dic);
}
class DBOperator
{
private DBFactory dbf;
private IDbConnection dbconn;
public DBOperator(DBFactory dbf)
{
this.dbf = dbf;
}
public void Open(string connstring)
{
dbconn = dbf.GetDBConnection();
dbconn.ConnectionString = connstring;
dbconn.Open();
}
public void Close()
{
dbconn.Close();
}
public DataSet ExecSQL(string sql)
{
IDbCommand dbc = dbf.GetDBCommand();
dbc.Connection = dbconn;
dbc.CommandText = sql;
IDbDataAdapter ida = dbf.GetDataAdapter(dbc);
DataSet ds = new DataSet();
ida.Fill(ds);
return ds;
}
public void ExeNoneSQL(string sql)
{
IDbCommand dbc = dbf.GetDBCommand();
dbc.Connection = dbconn;
dbc.CommandText = sql;
dbc.ExecuteNonQuery();
}
}