the .Read method of datareader does two things, 1) returns true or false based on the recordcount 2) moves the pointer to the next record. so, suppose I fetch a single record from database and, if datareader.read()=true then some code goes here....... end if
my question is what will be the datareader pointer position. i think technically it should move to EOF of datareader but actually it does not. how is that possible? thanks
You're right in 1 and 2. Remember that the DataReader's initial position is just before the first row, so when you call Read() for the first time, the reader now points to the first row.
mp417
Contributor
2658 Points
549 Posts
simple question about datareader
Sep 12, 2003 07:25 AM|LINK
Stanley Tan
Contributor
2035 Points
405 Posts
Re: simple question about datareader
Sep 12, 2003 08:00 AM|LINK
theSpoke Blog
sganti
Member
43 Points
32 Posts
Re: simple question about datareader
May 14, 2008 01:01 PM|LINK
I need to get single row of the Datareader at a time into a datatable.How can I do that?
zirmandli
Member
750 Points
110 Posts
Re: simple question about datareader
May 16, 2008 11:53 AM|LINK
Hi
Instead of using DateReader, u can use Dataset
here i give u example for that
DataSet ds = db.ExecuteDataSet(dbCommandWrapper);
DataTable
ret = ds.Tables[0];and then check
if( ds.Tables[0].Rows.Count == 0 ) return ;else
foreach(DataRow row in ret.Rows){
//Do your code for every row inLike
Contactus_id = (
int)row["Contactus_id"];}
-- Benazir Mandli