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

实现

示例

以下示例创建 OdbcConnectionOdbcCommandOdbcDataReader。 该示例通读数据,将其写入控制台。 最后,该示例关闭 , 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

适用于

另请参阅