共用方式為


OracleDataReader.Read 方法

定義

OracleDataReader 推進到下一筆記錄。

public:
 virtual bool Read();
public:
 override bool Read();
public bool Read ();
public override bool Read ();
abstract member Read : unit -> bool
override this.Read : unit -> bool
override this.Read : unit -> bool
Public Function Read () As Boolean
Public Overrides Function Read () As Boolean

傳回

如果有多個資料列,則為 true;否則為 false

實作

範例

下列範例會 OracleConnection建立 、、 OracleCommandOracleDataReader。 此範例會讀取數據,並將其寫出至主控台。 最後,此範例會 OracleDataReader關閉 ,然後關閉 OracleConnection

private static void ReadData(string connectionString)
{
    string queryString = "SELECT OrderID, CustomerID FROM Orders";
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();
        OracleDataReader reader;
        reader = command.ExecuteReader();

        // Always call Read before accessing data.
        while (reader.Read())
        {
            Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetString(1));
        }

        // Always call Close when done reading.
        reader.Close();
    }
}
Public Sub ReadData(ByVal connectionString As String)
    Dim queryString As String = _
        "SELECT OrderID, CustomerID FROM Orders"

    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString, connection)
        connection.Open()

        Dim reader As OracleDataReader
        reader = command.ExecuteReader()

        ' Always call Read before accessing data.
        While reader.Read()
            Console.WriteLine(reader.GetInt32(0) & ", " & reader.GetString(1))
        End While

        ' Always call Close when done reading.
        reader.Close()
    End Using
End Sub

備註

OracleDataReader 的預設位置較第一筆記錄早。 因此,您必須呼叫 Read 以開始存取任何數據。

任何指定時間都可以開啟一個 OracleDataReader 以上的 。

適用於