问一个DbProviderFactory的问题
请问
使用
DbProviderFactory dbfactory = DbProviderFactories.GetFactory( "System.Data.SqlClent ");
DbDataAdapter dbDataAdapter = dbfactory.CreateDataAdapter();
跟使用
DbDataAdapter dbDataAdapter = new SqlDataAdapter();
这两者有什么区别吗?
为什么还要多一个 DbProviderFactory 工厂
我直接指定一个枚举
public enum DbType
{
SqlServer,
Oledb,
Oracle,
Odbc
}
然后写方法
public static DbDataAdapter GetDataAdapter(DbType dbType)
{
DbDataAdapter Ada;
switch (dbType)
{
case DbType.SqlServer:
Ada = new SqlDataAdapter();
break;
case DbType.Oracle:
Ada = new OracleDataAdapter();
break;
case DbType.Oledb:
default:
Ada = new OleDbDataAdapter();
break;
case DbType.Odbc:
Ada = new OdbcDataAdapter();
break;
}
return Ada;