473,769 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between SQLDataReader and IDATAREADER...?

What is the difference between SqlDataReader and IDataReader ...? kindly with small example...
Mahesh~
Dec 1 '05 #1
4 4601
IDataReader is the interface for all Datareader classes. SqlDataReader is a
SQL Server - specific implementation of IDataReader. OracleDataReade r is the
Oracle - specific implementation. SQLiteDataReade r --- 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.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~

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.c om> wrote in message
news:%2******** ********@TK2MSF TNGP12.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
2363
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: ************************************************* public void Export2CSV(){
5
6594
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, M from Students WHERE (SSN = " + " '" + ProposedValue + "')", _ mySqlConnection) Try mySqlConnection.Open()
2
1566
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 closes the IDataReader? If i didn't close it explicitly, the IDataReader remains open untill GC will clean it?
2
6425
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 4 columns in this table as follow: Column1 | Column2 | Column3 | Column4 |
2
16451
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 SqlCommand.ExecuteReader(). Something like: MyDbClass db = new MyDbClass("SELECT * FROM tblUsers");
13
2864
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 reader.Read(), it has a row with 13 data columns, but they're all empty. So, my GetInt() function throws an error. When it jumps to the catch(), reader's columns then show the proper data. What gives? I have reader._data (which is the ID...
3
2831
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 strLastName = rs.getString( "LastName" );
0
1315
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. Using N-Tier architecture I keep recieving an object reference required error. Here's my code: Home.aspx.cs
3
1852
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 close method as well. So when the query runs the data reader has data but after the close is called the data reader becomes null. Is there a way I can preserver the data reader after closing the connection?? Thanks.
0
9579
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.