OracleDataReader.GetOrdinal(String) メソッド

定義

列の名前を指定して、列の序数を取得します。Gets the column ordinal, given the name of the column.

public:
 virtual int GetOrdinal(System::String ^ name);
public:
 override int GetOrdinal(System::String ^ name);
public int GetOrdinal (string name);
public override int GetOrdinal (string name);
abstract member GetOrdinal : string -> int
override this.GetOrdinal : string -> int
override this.GetOrdinal : string -> int
Public Function GetOrdinal (name As String) As Integer
Public Overrides Function GetOrdinal (name As String) As Integer

パラメーター

name
String

列の名前。The name of the column.

戻り値

Int32

0 から始まる列序数。The zero-based column ordinal.

実装

GetOrdinal メソッドの使用方法を次の例に示します。The following example demonstrates how to use the GetOrdinal method.

Public Sub ReadOracleData(ByVal connectionString As String)  

    Dim queryString As String = "SELECT OrderID, CustomerID FROM Orders"  
    Dim connection As New OracleConnection(connectionString)  
    Dim command As New OracleCommand(queryString, connectionString)  

    connection.Open()  

    Dim reader As OracleDataReader = command.ExecuteReader()  

    Dim custIdCol As Integer = reader.GetOrdinal("CustomerID")  

    Do While reader.Read()  
        Console.WriteLine("CustomerID = {0}", reader.GetString(custIdCol))  
    Loop  

    reader.Close()  
    connection.Close()  
End Sub  
public void ReadOracleData(string connectionString)  
{  
    string queryString = "SELECT OrderID, CustomerID FROM Orders";  
    OracleConnection connection = new OracleConnection(connectionString);  
    OracleCommand command = new OracleCommand(queryString,connection);  

    connection.Open();  
    OracleDataReader reader = command.ExecuteReader();  

    int custIdCol = reader.GetOrdinal("CustomerID");  

    while (reader.Read())  
        Console.WriteLine("CustomerID = {0}", reader.GetString(custIdCol));  

    reader.Close();  
    connection.Close();  
}  

注釈

GetOrdinal は、まず大文字と小文字を区別して参照を実行します。GetOrdinal performs a case-sensitive lookup first. 失敗した場合、次に大文字と小文字を区別せずに検索が行われます。If it fails, a second case-insensitive search is made. IndexOutOfRange0 から始まる列序数が見つからない場合、メソッドは例外をスローします。The method throws an IndexOutOfRange exception if the zero-based column ordinal is not found.

GetOrdinal では、カタカナの全角と半角が区別されません。GetOrdinal is kana-width insensitive.

序数に基づく参照は名前による参照よりも効率的であるため、ループ内で GetOrdinal を呼び出すのは非効率的です。Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. 代わりに、を GetOrdinal 一度呼び出し、ループ内で使用するために結果を整数変数に代入します。Instead, call GetOrdinal once and then assign the results to an integer variable for use within the loop.

適用対象