2010-07-13 64 views
2

ADO.net的一大優點是您不必知道您正在使用哪種連接/命令(基於接口的編程)。您可以使用連接來創建命令,並使用命令來創建閱讀器。在不知道驅動程序類型的情況下創建適配器

IDbConnectin con = CreateConnection(_connectionString); //factory method 
IDbCommand cmd = con.CreateCommand(); 
IDataReader reader = cmd.ExecuteReader(); 

但是,如何以同樣的方式創建一個IDataAdapter?

回答

3
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. 

我已經做了你所要求的,但我找不到代碼。我會盡快更新答案。

+0

無需更新。感謝您指點我正確的方向。 – jgauffin 2010-07-13 10:00:05

+0

在這裏找到一篇關於整個概念的文章:http://msdn.microsoft.com/en-us/library/t9f29wbk(v=VS.80).aspx – jgauffin 2010-07-13 10:39:53

+0

當然是,DbProviderFactory。好的! – Steven 2010-07-13 11:00:32

相關問題