I would advice to look at this simple article first:
Using ADO.NET for beginners[
^].
Take a look at the diagram where you see relationships between
DbConnection
,
DataAdapter
and
DataReader
. The problem is: you cannot abstract connection from data provider. It is provider-specific. You need to create an instance of
DataAdapter
,
DataReader
or both using your connection string and some specific data provider you use. When you do it, you can return
DataReader
as the instance of the interface
System.Data.IDataReader
and the
DataAdapter
as the instance of the interface
System.Data.IDataAdapter
,
System.Data.IDbDataAdapter
or the abstract class
System.Data.Common.DbDataAdapter
(with some more capabilities), depending on your task. These instances are agnostic to the provider and you can use them in any application.
—SA