Reads a forward-only stream of rows from Oracle.
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) {
OracleConnection oracleConnection = new OracleConnection(myConnString);
OracleCommand oracleCommand = (OracleCommand)oracleConnection.CreateCommand();
oracleCommand.CommandText = "SELECT DeptNo, DName, Loc FROM Test.Dept";
oracleConnection.Open();
OracleDataReader oracleReader = oracleCommand.ExecuteReader();
try {
// Always call Read before accessing data.
while (oracleReader.Read()) {
Console.WriteLine(oracleReader.GetInt32(0).ToString() + " " +
oracleReader.GetString(1) + " " + oracleReader.GetString(2));
}
}
finally {
// always call Close when done reading.
oracleReader.Close();
// Close the connection when done with it.
oracleConnection.Close();
}
} |
|
|---|
Public Sub ReadMyData(ByVal myConnString As String)
Dim oracleConnection As New OracleConnection(myConnString)
Dim oracleCommand As OracleCommand = oracleConnection.CreateCommand()
oracleCommand.CommandText = "SELECT DeptNo, DName, Loc FROM Test.Dept"
oracleConnection.Open()
Dim oracleReader As OracleDataReader = oracleCommand.ExecuteReader()
Try
' Always call Read before accessing data.
While oracleReader.Read()
Console.WriteLine(String.Concat(oracleReader.GetInt32(0).ToString(), " ", _
oracleReader.GetString(1), " ", oracleReader.GetString(2)))
End While
Finally
' always call Close when done reading.
oracleReader.Close()
' Close the connection when done with it.
oracleConnection.Close()
End Try
End Sub |