System.Data.OleDb Namespace OleDbDataReader Class
Closes the OleDbDataReader object.
[ VB ]
NotOverridable Public Sub Close ( )
[ C# ]
public void Close ( );
[ C++ ]
public: __sealed void Close ( );
[ C++ ]
public function Close ( );
You must explicitly call the Close method when you are through using the OleDbDataReader to use the associated OleDbConnection for any other purpose.
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, then 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 ( );
}
Public Sub ReadMyData ( connString As String )
Dim query As String = "SELECT OrderID, CustomerID FROM Orders"
Dim myConn As New OleDbConnection ( connString )
Dim myCommand As New OleDbCommand ( query, myConn )
myConn.Open ( )
Dim myReader As OleDbDataReader = myCommand.ExecuteReader ( )
' loop thru the reader.
While myReader.Read ( )
Response.Write ( myReader.GetInt32 ( 0 ).ToString ( ) + ", " myReader.GetString ( 1 ) )
End While
' always close the reader when done.
myReader.Close ( )
' always close the connection when done.
myConn.Close ( )
End Sub |
|
C# |
VB |
OleDbDataReader Members