asp.net.ph

OleDbDataReader.Read Method

System.Data.OleDb Namespace   OleDbDataReader Class


Advances the data reader to the next record.

[ VB ]
NotOverridable Public Function Read ( ) As Boolean

[ C# ]
public bool Read ( );

[ C++ ]
public: __sealed bool Read ( );

[ JScript ]
public function Read ( ) : Boolean

Return Value

true if another record could be read; otherwise, false.

Remarks

The default positioning is prior to the first record, therefore you must call Read before accessing any data.

While the data reader is in use, the associated connection is busy serving the data reader. This will be the case until Close is called.

Example

The following example initializes an OleDbConnection, an OleDbCommand, and an OleDbDataReader. The example reads through the data, writing each row of data to the page. Finally, the example closes the reader and the connection.

void ReadMyData ( string connString ) {
   OleDbConnection myConn = new OleDbConnection ( connString );
   string query = "SELECT OrderID, CustomerID FROM Orders";
   OleDbCommand myCommand = new OleDbCommand ( query, myConn );
   myConn.Open ( );
   OleDbDataReader myReader = myCommand.ExecuteReader ( );

   // loop thru the reader.
   while ( myReader.Read ( ) ) {
      Response.Write ( myReader.GetInt32 ( 0 ) + ", " + myReader.GetString ( 1 ) );
   }
   // always close the reader when done.
   myReader.Close ( );
   // always close the connection when done.
   myConn.Close ( );
}
  C# VB

See Also

OleDbDataReader Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph