DataReader

  • Thread starter Thread starter A.J
  • Start date Start date
A

A.J

1. When ever an object of datareader is created ex:-->
dim rdr as oledbdatareader
why we are not using the new operator?

2. Could you please give me detailed overview of datareader
ie.how it works,the different member functions of this class etc.
 
Please see inline comments...


A.J said:
1. When ever an object of datareader is created ex:-->
dim rdr as oledbdatareader
why we are not using the new operator?

Thats the way it works...

You would use a datareader somthing like:
rdr = myDataCommand.ExecuteReader();

Extract from Microsoft Documentation: (http://tinyurl.com/cgcnp)

'To create an OleDbDataReader, you must call the ExecuteReader method of the
OleDbCommand object, rather than directly using a constructor.'

2. Could you please give me detailed overview of datareader
ie.how it works,the different member functions of this class etc.

Start here:
http://tinyurl.com/35abn
 
AJ:

I see that some others have answered the question already but I'll throw in
my two cents. For a DataReader object to be of ANY Value, it must operate
in the context of a database command and an open and avaliable connection.
I know - by virtue of the fact you can't declare a "new" dataReader, this is
necessarily so physically, but even logically, there's NOTHING that you
could do with a datareader if you didn't have a command associated with it
and that command having a connection. A dataTable for instance, doesn't
need a Command to be valid. A DataAdapter could similarly be used for more
than one purpose, but a DataReader can only be used to iterate through some
data forward only and to that end, having it only come to life via an
ExecuteReader is logically a pretty sensible thing.

The main methods you'll be concerned with are .Read(),NextResult() and the
GetXXX. I see there's a link provided by one of the other respondents so I
won't elaborate too much here. If you have any questions though getting one
working, please let me know and I'll do waht I can to get you through it.
 
May be we are not using the new operator while creating an object of
datareader as we are creating an instance. So at this stage memory will
not be allocated to the object. This is the reason which i can figure
out. Please assist.
 
Correct, saying:

dim rdr as OleDbDataReader

is simplying declaring a new object of type DataReader. It's value is null,
so takes up no memory(well maybe a tiny bit...).
It's not until you instantiate it (using the .ExecuteDataReader method of a
Command object) that is becomes an actual object taking up memory.
 
AJ - there's nothing that can be done with a new DataReader as such so there
would not be any reason to create such a thing. THe command objects creates
a new one when you call executereade - it's merely a different way to get to
the exact same point.
 
AJ - other than what's been answered, what is it that you seek assistance
with?
 
Thanks a lot for helping me, I am through with this concept (hope so).
I will be back with more queries
 
Glad to have been of help. ADo.NEt can be a little rough getting your arms
around at first, but once you do you'll be glad you did. If I can help in
the meantime, pleease don't hesitate to ask.

Cheers,

Bill
 
Back
Top