|
-
Jun 27th, 2010, 11:39 PM
#1
Thread Starter
Fanatic Member
DataReader
I have been studying about the DataReader in the msdn from a couple of hours and i habe seen that they are using this term:Read only Forward only a lot of times for the DataReader but i cant understand why?Why are DataReaders Read only Forward only?
please explain with a simple example sir
-
Jun 28th, 2010, 12:06 AM
#2
Re: DataReader
A DataReader provides access to the result set of a query.
You can only use the DataReader to read that data. It cannot be used to make any changes to the database. That's why they say that it is read-only.
You cannot move randomly through the result set. Once you advance to a record you cannot then move back to the previous record. That's why they say that it is forward only.
If you want your data to be read/write and/or you want random access to it, you should be using a DataAdapter and a DataTable rather than a DataReader.
-
Jun 28th, 2010, 12:12 AM
#3
Thread Starter
Fanatic Member
Re: DataReader
Also i saw in the msdn that by default,the datareader stores one row at a time in the memory.
 Originally Posted by jmcilhinney
Once you advance to a record you cannot then move back to the previous record.
as you said,advancing to a record you cannot then move back to the previous record;does it mean that advancing to a record,the previous record is deleted from the memory and cannot be retrieved again until the code for reading data source via the datareader is again executed?
-
Jun 28th, 2010, 12:26 AM
#4
Re: DataReader
If you could retrieve the data from a previous record after advancing then that would be going backwards, wouldn't it? "Forward only" means exactly what it says.
-
Jun 28th, 2010, 12:37 AM
#5
Thread Starter
Fanatic Member
Re: DataReader
one more thing:
the DataAdapter uses the fill method to add data to the DataSet from the data source and the fill method uses the DataReader object implicitly to do the needful.........can you please add something to this?
-
Jun 28th, 2010, 12:44 AM
#6
Re: DataReader
The statement pretty much speaks for itself.
-
Jun 28th, 2010, 01:07 AM
#7
Thread Starter
Fanatic Member
Re: DataReader
but my confusion lies in the fact that when the fill method of the dataadapter is called to fill the dataset,then is it the selectcommand of the dataadapter that fills the dataset with the data which it returns or is it the datareader that returns the data to fill the dataset?
Now i am getting confused by reading the msdn.........Please help
-
Jun 28th, 2010, 01:14 AM
#8
Re: DataReader
How do you use a DataReader? You create a Command, call ExecuteReader and then read the data, right?
What is the SelectCommand of a DataAdapter? It's a Command. When you call Fill on a DataAdapter, it calls ExecuteReader on the SelectCommand, reads the data and puts it into a DataTable.
If you wanted to you could bypass the Fill method and call ExecuteReader on the SelectCommand yourself, but why would you want to do that when the DataAdapter can do it for you?
-
Jun 28th, 2010, 01:28 AM
#9
Thread Starter
Fanatic Member
Re: DataReader
and what is the purpose of the dataadapter then?it just works as a bridge between the data source and the dataset and thats it?
-
Jun 28th, 2010, 01:38 AM
#10
Thread Starter
Fanatic Member
Re: DataReader
one more thng:the datareader is responsible for returning the column names and the types that are used to create tables in the DataSet;how this is done?
-
Jun 28th, 2010, 02:13 AM
#11
Thread Starter
Fanatic Member
Re: DataReader
Column types are created in the dataset as .NET Framework types.........what does it means?
-
Jun 28th, 2010, 02:24 AM
#12
Re: DataReader
 Originally Posted by HowTo
one more thng:the datareader is responsible for returning the column names and the types that are used to create tables in the DataSet;how this is done?
If you want to know how to get schema information from a DataReader then check out the documentation for the the appropriate DataReader class. If you look at the members it exposes you should be able to tell fairly easily.
If you're asking what the mechanism used under the hood is then that depends on the data source. That's a low level detail that you really don't need to care about as a .NET developer.
-
Jun 28th, 2010, 02:30 AM
#13
Re: DataReader
 Originally Posted by HowTo
Column types are created in the dataset as .NET Framework types.........what does it means?
In the database your columns might be data types like 'text' or 'varchar' or the like, depending on the column properties and the data source. When that data is retrieved into a .NET app though, all columns that contain text will be mapped to a DataColumn whose DataType is String. String is the .NET Framework type that stores text so all text columns map to that type. The same goes for other columns. It doesn't matter what their data source-specific data type is, but only what type of data they store, e.g. all columns containing dates map to DateTime, etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|