SqlDataReader implements the IDataReader interface. Thus, all other ADO.NET drivers (Oracle, MySql, etc.). You can use IDataReader , so if you plan to change the database engine once, you donβt have to rewrite all of your SqlDataReader links.
The same goes for IDbConnection , IDbCommand , etc. Of course, when creating a connection, you need to specify which engine you are using, but in addition to this, you will never have to explicitly determine which one you are using.
Note that IDataReader does not have a HasRows property, and you must use the Create...() methods to create the commands and parameters:
IDbCommand command = myDbConnection.CreateCommand();
Instead:
SqlCommand command = new SqlCommand(myDbConnection);
EDIT: instead of using interfaces, you can use the abstract DbConnection class inherited by all ADO.NET providers. They provide some additional features, such as retrieving schema information and the aforementioned HasRows property for DbDataReader . See http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/759fa77b-8269-4c4a-be90-3c2bdce61d92/ , why the interface could not cope with the abstract class.
C.Evenhuis
source share