共用方式為


OdbcDataReader.Read 方法

定義

OdbcDataReader 推進到下一筆記錄。

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

傳回

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

實作

範例

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

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

備註

的預設位置 OdbcDataReader 是在第一筆記錄之前。 因此,您必須呼叫 Read 以開始存取任何數據。

OdbcDataReader在使用 時,相關聯的 OdbcConnection 會忙碌地提供服務,直到您呼叫 Close為止。

適用於

另請參閱