Hi Export,
I want to write a class to deal with all db tier with different platform,
but when I using a DbAdapter (superclass) pointer to point a OleDBAdapter
(subclasse) instance, it said the selectCommand is protected.
How can I do that polymorphism?
below is my class:
public class db
{
protected System.ComponentModel.Component dbCon;
protected System.Data.Common.DbDataAdapter dbDataAdapter;
protected string dbType;
public db(String dbType, string ConnectionStr)
{
//
// TODO: Add constructor logic here
//
switch (dbType)
{
case "mysql":
dbCon = new System.Data.Odbc.OdbcConnection(ConnectionStr);
dbDataAdapter = new System.Data.Odbc.OdbcDataAdapter();
break;
default:
dbCon = new System.Data.OleDb.OleDbConnection(ConnectionStr);
dbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
break;
};
this.dbType = dbType;
}
public DataSet setSelectCommand(string sql)
{
DataSet rs = new DataSet();
this.dbDataAdapter.SelectCommand.Connection = dbCon;
this.dbDataAdapter.SelectCommand.CommandText = sql;
this.dbDataAdapter.Fill(rs);
return rs;
}
}