471,305 Members | 1,214 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

DB Polymorphism

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;
}
}
Jul 22 '05 #1
0 958

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sarathy | last post: by
11 posts views Thread by chsalvia | last post: by
17 posts views Thread by Bart Friederichs | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.