simple question about datareader RRS feed

  • Question

  • User1605082899 posted
    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
    Friday, September 12, 2003 3:25 AM

All replies

  • User1165667961 posted
    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.
    Friday, September 12, 2003 4:00 AM
  • User2121754339 posted

    I need to get single row of the Datareader at a time into a datatable.How can I do that?

    Wednesday, May 14, 2008 9:01 AM
  • User-1846563363 posted


    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 ;


    foreach(DataRow row in ret.Rows)


    //Do your code for every row in  


         Contactus_id = (int)row["Contactus_id"];



    Friday, May 16, 2008 7:53 AM