471,319 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Difference between SQLDataReader and IDATAREADER...?

What is the difference between SqlDataReader and IDataReader ...? kindly with small example...
Mahesh~
Dec 1 '05 #1
4 4400
IDataReader is the interface for all Datareader classes. SqlDataReader is a
SQL Server - specific implementation of IDataReader. OracleDataReader is the
Oracle - specific implementation. SQLiteDataReader --- etc.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mahesh Kumar.R" wrote:
What is the difference between SqlDataReader and IDataReader ...? kindly with small example...
Mahesh~

Dec 1 '05 #2
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.ExecuteReader();

and

dr = cmdO.ExecuteReader()

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(ourConnectionString);
cmd = new SqlCommand(someSqlText);
dr = cmd.ExecuteReader();

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(ourConnectionString);
cmd = new OledbCommand(someSqlText);

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~

Dec 1 '05 #3
Sorry that should have read Abstract Factory not Object Factory

http://www.dofactory.com/Patterns/PatternAbstract.aspx

Simon

Mahesh Kumar.R wrote:
What is the difference between SqlDataReader and IDataReader ...? kindly
with small example...
Mahesh~

Dec 1 '05 #4
Well said and I'm complete now.. Thanks to Simon and Peter,,
Mahesh~

"Simon" <si****************@nodomain.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Sorry that should have read Abstract Factory not Object Factory

http://www.dofactory.com/Patterns/PatternAbstract.aspx

Simon

Mahesh Kumar.R wrote:
What is the difference between SqlDataReader and IDataReader ...? kindly
with small example...
Mahesh~

Dec 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Franck Diastein | last post: by
5 posts views Thread by Woody Splawn | last post: by
2 posts views Thread by יוני גולדברג | last post: by
2 posts views Thread by teresa | last post: by
2 posts views Thread by jarod1701 | last post: by
3 posts views Thread by CSharper | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.