Connecting Tech Pros Worldwide Forums | Help | Site Map

Difference between SQLDataReader and IDATAREADER...?

Mahesh Kumar.R
Guest
 
Posts: n/a
#1: Dec 1 '05
What is the difference between SqlDataReader and IDataReader ...? kindly with small example...


Mahesh~

Peter Bromberg [C# MVP]
Guest
 
Posts: n/a
#2: Dec 1 '05

re: Difference between SQLDataReader and IDATAREADER...?


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:
[color=blue]
> What is the difference between SqlDataReader and IDataReader ...? kindly with small example...
>
>
> Mahesh~[/color]
Simon
Guest
 
Posts: n/a
#3: Dec 1 '05

re: Difference between SQLDataReader and IDATAREADER...?


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:[color=blue]
> What is the difference between SqlDataReader and IDataReader ...? kindly
> with small example...
>
>
> Mahesh~[/color]
Simon
Guest
 
Posts: n/a
#4: Dec 1 '05

re: Difference between SQLDataReader and IDATAREADER...?


Sorry that should have read Abstract Factory not Object Factory

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

Simon

Mahesh Kumar.R wrote:[color=blue]
> What is the difference between SqlDataReader and IDataReader ...? kindly
> with small example...
>
>
> Mahesh~[/color]
Mahesh Kumar.R
Guest
 
Posts: n/a
#5: Dec 2 '05

re: Difference between SQLDataReader and IDATAREADER...?


Well said and I'm complete now.. Thanks to Simon and Peter,,
Mahesh~

"Simon" <simon_nospam_rigby@nodomain.com> wrote in message
news:%23NUslFo9FHA.1188@TK2MSFTNGP12.phx.gbl...[color=blue]
> Sorry that should have read Abstract Factory not Object Factory
>
> http://www.dofactory.com/Patterns/PatternAbstract.aspx
>
> Simon
>
> Mahesh Kumar.R wrote:[color=green]
> > What is the difference between SqlDataReader and IDataReader ...? kindly
> > with small example...
> >
> >
> > Mahesh~[/color][/color]


Closed Thread


Similar C# / C Sharp bytes