473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4582
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
5
by: Woody Splawn | last post by:
I have some code that looks like this: Dim SSN, LName, FName, M As String mySqlConnection = New SqlConnection(myConnectionString) Dim sql_Command As New SqlCommand( _ "Select SSN, LName, FName,...
2
by: יוני גולדברג | last post by:
Hi, In few places within my code the business object pass IDataReader to the GUI. Suddenly i noticed that nowhere in the code the IDataReader is being closed. Does the data binding operation...
2
by: teresa | last post by:
Hi Everyone, I appreciate any help if any of you know or have used this method before and can give me some suggestion. It's a bit difficult to explain: Here is my table: Table1: there are...
2
by: jarod1701 | last post by:
Hi everyone, is there a way to access every record from a SqlDataReader via "foreach" ? I want to write a class which (besides doing some other stuff) retrieves a recordset using...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
3
by: Frank Milverckowitz | last post by:
Hi, Newbie question about SqlDataReader column value access... In java jdbc code to get a value from a table column we can pass the column name (instead of an int index or offset): String...
0
by: rsdev | last post by:
Hi, I am new to ASP.NET and I am trying to build a CMS application using theBeerHouse SK. I am adapting the Datareader to collect information from an SQL database and send it to an HtmlHeader. ...
3
by: CSharper | last post by:
I have a common program where I have a method which make a sql connection and then prepares a SqlDataReader that is passed to the calling method. But in the common method, I have the connection...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.