Export (0) Print
Expand All

OracleDataReader.GetOrdinal Method

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets the column ordinal, given the name of the column.

[Visual Basic]
Public Overridable Function GetOrdinal( _
   ByVal name As String _
) As Integer Implements IDataRecord.GetOrdinal
[C#]
public virtual int GetOrdinal(
 string name
);
[C++]
public: virtual int GetOrdinal(
 String* name
);
[JScript]
public function GetOrdinal(
   name : String
) : int;

Parameters

name
The name of the column.

Return Value

The zero-based column ordinal.

Implements

IDataRecord.GetOrdinal

Remarks

GetOrdinal performs a case-sensitive lookup first. If it fails, a second case-insensitive search is made.

GetOrdinal is kana-width insensitive.

Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. Instead, call GetOrdinal once and then assign the results to an integer variable for use within the loop.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the GetOrdinal method.

[Visual Basic] 
Public Sub ReadMyData(myConnString As String)

  Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
  Dim myConnection As New OracleConnection(myConnString)
  Dim myCommand As New OracleCommand(mySelectQuery, myConnection)

  myConnection.Open()

  Dim myReader As OracleDataReader = myCommand.ExecuteReader()

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

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

  myReader.Close()
  myConnection.Close()
End Sub

[C#] 
public void ReadMyData(string myConnString)
{
    string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";
    OracleConnection myConnection = new OracleConnection(myConnString);
    OracleCommand myCommand = new OracleCommand(mySelectQuery,myConnection);

    myConnection.Open();
    OracleDataReader myReader = myCommand.ExecuteReader();

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

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

    myReader.Close();
    myConnection.Close();
}

[C++] 
public:
    void ReadMyData(String* myConnString)
    {
        String* mySelectQuery = S"SELECT OrderID, CustomerID FROM Orders";
        OracleConnection* myConnection = new OracleConnection(myConnString);
        OracleCommand* myCommand = new OracleCommand(mySelectQuery, myConnection);

        myConnection->Open();
        OracleDataReader* myReader = myCommand->ExecuteReader();

        int custIdCol = myReader->GetOrdinal(S"CustomerID");

        while (myReader->Read())
            Console::WriteLine(S"CustomerID = {0}", myReader->GetString(custIdCol));

        myReader->Close();
        myConnection->Close();
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

OracleDataReader Class | OracleDataReader Members | System.Data.OracleClient Namespace | GetName

Show:
© 2014 Microsoft