Sergi
Is this what your trying to achieve...
abstract class MyBaseClass
{
private IDbConnection _connection;
public virtual IDbConnection Connection
{
get { return _connection; }
set { _connection = value; }
}
public MyBaseClass()
{
Connection = CreateConnectio n();
}
protected abstract IDbConnection CreateConnectio n();
public virtual void DoSomeSql()
{
if ( Connection.Stat e != ConnectionState .Open )
{
Connection.Open ();
}
using ( IDbCommand command = Connection.Crea teCommand() )
{
//If it's parameterised sql you'll need to check what the placeholders
should be for the DB type
//@=sql server, ?=odbc, :=oracle
command.Command Text = "SELECT * FROM T_SOME_DATA";
using ( IDataReader reader = command.Execute Reader() )
{
while ( reader.Read() )
{
//DoSomething
}
}
}
}
}
class MyOracleVersion : MyBaseClass
{
protected override IDbConnection CreateConnectio n()
{
return new OracleConnectio n( "Data Source=emp;user
id=scott;passwo rd=tiger" );
}
}
class MySqlServerVers ion : MyBaseClass
{
protected override IDbConnection CreateConnectio n()
{
return new SqlConnection( "How should I know this, I use Oracle" );
}
}
HTH
Glenn
"mrclash" <se************ @gmail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
Hello,
I have a class that uses some variables to access a sql database, and I
want to make a derived class that inherits all the methods of this
class, because the derived one will do exactly the same process that
the parent one, but with a postgres database, thus I've got to use
diferent type variables to acces the database.
There's one big function in the class that does all the DB stuff, and I
want to know if there's any way to inherit the function but with only
changing the type of some vars inside this function.
Thanks!
Sergi