As stated IDataReader is the interface that all "concrete" dataReaders
implement. As an example:
IDataReader dr;
SqlCommand cmdS = new SqlCommand();
OledbCommand cmdO = new OledbCommand();
dr = cmdS.ExecuteRea der();
and
dr = cmdO.ExecuteRea der()
are both valid as dr will take an instance of any type that implements
IDataReader. This is particularly useful when you are writing code that
will target different data sources. You can extend this further by using
the Interfaces for other data access objects.
for example:
IDbConnection cn; // interface that all connection objects implement
IDbCommand cmd; // interface that all command objects implement
IDataReader dr;
cn = new SqlConnection(o urConnectionStr ing);
cmd = new SqlCommand(some SqlText);
dr = cmd.ExecuteRead er();
Assuming that you are doing other things with your data access objects
you only need to change the lines that create the instances of your
obects to make the code work with another data source.
eg
cn = new OledbConnection (ourConnectionS tring);
cmd = new OledbCommand(so meSqlText);
Take a look at the Object Factory design pattern which shows the true
power/reusability of this approach.
Hope this helps
Simon
Mahesh Kumar.R wrote:
What is the difference between SqlDataReader and IDataReader ...? kindly
with small example...
Mahesh~