c#下各种数据库操作的封装!(支持ACCESS,SQLSERVER,DB2,ORACLE,MYSQL)
【转】http://hi.baidu.com/hou5757219/blog/item/ce34f51956998d73dab4bd95.html
public enum DBType
...{
Access,
SQL,
DB2,
Oracle,
MySQL
}
public interface IDBAccess
...{
void Init(string strServer, string strDataBase, string strUser, string strPwd);
void Open();
void Close();
bool TestConn();
int RunNoQuery(string strCmd);
DataTable RunQuery(string strCmd);
DBType DBType ...{ get;}
int GetFiledMax(string strTable, string strField);
DataTable Tables ...{ get; }
DataTable GetColumns();
DataTable GetColumns(string strTable);
}
public static class DBAccessFactory
...{
public static IDBAccess Create(DBType type)
...{
IDBAccess IRet = null;
switch (type)
...{
case DBType.Access:
IRet = new Access(type);
break;
case DBType.SQL:
IRet = new SQL(type);
break;
default:
break;
}
return IRet;
}
private abstract class DBAccess : IDBAccess
...{
protected DbConnection m_oConn = null;
protected const string CON_strServer = "Server";
protected const string CON_strDataBase = "Data Source";
protected const string CON_strUser = "UID";
protected const string CON_strPwd = "PWD";
protected const string CON_strConnTimeOut &#