ADO.net 的一大优点是您不必知道您正在使用哪种连接/命令(基于接口(interface)的编程)。您可以使用连接来创建命令,并使用命令来创建读取器。
IDbConnectin con = CreateConnection(_connectionString); //factory method
IDbCommand cmd = con.CreateCommand();
IDataReader reader = cmd.ExecuteReader();
但是如何以同样的方式创建 IDataAdapter 呢?
最佳答案
Public Overridable Function CreateDataAdapter() As System.Data.Common.DbDataAdapter
Member of System.Data.Common.DbProviderFactory
Summary:
Returns a new instance of the provider's class that implements the System.Data.Common.DbDataAdapter class.
Return Values:
A new instance of System.Data.Common.DbDataAdapter.
我已经按照你的要求做了,但我找不到代码。我会尽可能更新答案。
关于c# - 在不知道驱动程序类型的情况下创建适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3234903/