各派生类的具体实现,此时只要实现DBAccess的各个虚函数即可。
private class Access : DBAccess
...{
public Access(DBType type)
: base(type)
...{
}
protected override void InitConn(string strServer, string strDataBase, string strUser, string strPwd)
...{
string strConn = "Provider = ";
switch (strDataBase.Substring(strDataBase.LastIndexOf('.') + 1).ToLower())
...{
case "mdb": // 2000, 2003
strConn += "Microsoft.Jet.OleDb.4.0;";
break;
case "accdb": // 2007
strConn += "Microsoft.ACE.OLEDB.12.0;";
break;
default:
throw (new Exception("Unknown Access Version."));
//break;
}
strConn += CON_strDataBase + " = " + strDataBase;
//strConn += CON_strUser + " = " + strUser;
//strConn += CON_strPwd + " = " + strPwd;
base.m_oConn = new OleDbConnection(strConn);
}
protected override DbCommand GetCmd(string strCmd)
...{
return new OleDbCommand(strCmd, (OleDbConnection)base.m_oConn);
}
protected override DbDataAdapter DbAdp
...{
get ...{ return new OleDbDataAdapter(); }
}
public override DataTable Tables
...{
get
...{
return ((OleDbConnection)base.m_oConn).GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] ...{ null, null, null, "Table" });
}
}
public override DataTable GetColumns()
...{
DataTable dt = new DataTable();
foreach (DataRow row in this.Tables.Rows)
...{
dt.Merge(this.GetColumns(row["TABLE_NAME"].ToString()));
}
return dt;
}
public override DataTable GetColumns(string strTable)
...{
return ((OleDbConnection)base.m_oConn).GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] ...{ null, null, strTable, null });
}
}
private class SQL : DBAccess
...{
public SQL(DBType type)
: base(type)
...{
}
protected override void InitConn(string strServer, string strDataBase, string strUser, string strPwd)
...{
string strConn = CON_strServer + " = " + strServer + ";";
strConn += CON_strDataBase + " = " + strDataBase + ";";
strConn += CON_strUser + " = " + strUser + ";";
strConn += CON_strPwd + " = " + strPwd + ";";
strConn += CON_strConnTimeOut;
base.m_oConn = new SqlConnection(strConn);
}
protected override DbCommand GetCmd(string strCmd)
...{
return new SqlCommand(strCmd, (SqlConnection)base.m_oConn);
}
protected override DbDataAdapter DbAdp
...{
get ...{ return new SqlDataAdapter(); }
}
public override DataTable Tables
...{
get ...{ return ((SqlConnection)base.m_oConn).GetSchema("Tables", null); }
}
public override DataTable GetColumns()
...{
return ((SqlConnection)base.m_oConn).GetSchema("Columns", null);
}
public override DataTable GetColumns(string strTable)
...{
return ((SqlConnection)base.m_oConn).GetSchema("Columns", new string[] ...{ null, null, strTable, null });
}
}