Close Method (OracleDataReader)
The following example creates a
OracleConnection, a
OracleCommand, and a
OracleDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
OracleDataReader, then the
OracleConnection.
|
|---|
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept";
OracleConnection oracleConnection = new OracleConnection(myConnString);
OracleCommand oracleCommand = new OracleCommand(mySelectQuery,oracleConnection);
oracleConnection.Open();
OracleDataReader oracleReader;
oracleReader = oracleCommand.ExecuteReader();
// Always call Read before accessing data.
while (oracleReader.Read()) {
Console.WriteLine(oracleReader.GetInt32(0) + ", " + oracleReader.GetString(1));
}
// always call Close when done reading.
oracleReader.Close();
// Close the connection when done with it.
oracleConnection.Close();
} |
|
|---|
Public Sub ReadMyData(myConnString As String)
Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
Dim oracleConnection As New OracleConnection(myConnString)
Dim oracleCommand As New OracleCommand(mySelectQuery, oracleConnection)
oracleConnection.Open()
Dim oracleReader As OracleDataReader
oracleReader = oracleCommand.ExecuteReader()
' Always call Read before accessing data.
While oracleReader.Read()
Console.WriteLine(oracleReader.GetInt32(0).ToString() + ", " _
+ oracleReader.GetString(1))
End While
' always call Close when done reading.
oracleReader.Close()
' Close the connection when done with it.
oracleConnection.Close()
End Sub |