views:

31

answers:

1

One of the great things with ADO.net is that you dont have to know which kind of connections/commands that you are using (interface based programming). You can use a connection to create a command, and command to create a reader.

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

But how do I create a IDataAdapter in the same way?

+2  A: 
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.

I have done what you are asking, but I cannot find the code. I will update answer when I can.

AMissico
No need to update. Thanks for pointing me in the right direction.
jgauffin
Found a article here about the whole concept: http://msdn.microsoft.com/en-us/library/t9f29wbk(v=VS.80).aspx
jgauffin
Yes of course, the DbProviderFactory. Good one!
Steven
@jgauffin: Yes, that was one of the links I tried to find earlier. I was able to create a data-access-layer that worked against SqlCe, OleDb, and SqlClient. All I had to do was pass an enumeration for the provider I wanted. Connection string read from .config. It worked perfectly.
AMissico
I will still try to update answer to show technique for others.
AMissico