下面是具體的操作類型,SqlServer、Oracle、OleDb都是繼承自DataHelper的,但並未為每一個操作類都寫出各種數據操作的方法,這也主要是為了好維護,這幾個類同時實現IDataProvider接口,這個接口就是為每種類型提供DbConnection、DbParameter、DataAdapter、DbCommand等。如SqlServer裡是這樣寫到的:
public class SqlServer : DataHelper, IDataProvider
{
#region IDataConverter
IDbConnection IDataProvider.GetDbConnection()
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.StateChange += new StateChangeEventHandler(base.OnStateChange);
return conn;
}
IDbDataAdapter IDataProvider.GetDataAdapter()
{
return new SqlDataAdapter();
}
IDataParameter IDataProvider.GetParameter()
{
return new SqlParameter();
}
IDataParameter[] IDataProvider.GetParameters(int Count)
{
return new SqlParameter[Count];
}
IDbCommand IDataProvider.GetCommand(IDbCommand command)
{
return command as SqlCommand;
}
void IDataProvider.GetCommandBuilder(IDbDataAdapter DataAdapter, DataTable DataTable, DataViewRowState dataVIEwRowState)
{
SqlDataAdapter adapter = (SqlDataAdapter)DataAdapter;
SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter);
}
#endregion
}