CommandText Property

OracleCommand.CommandText Property

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

Gets or sets the SQL statement or stored procedure to execute against the database.

[Visual Basic]
Public Overridable Property CommandText As String  Implements _
   IDbCommand.CommandText
[C#]
public virtual string CommandText {get; set;}
[C++]
public: __property virtual String* get_CommandText();
public: __property virtual void set_CommandText(String*);
[JScript]
public function get CommandText() : String;
public function set CommandText(String);

Property Value

The SQL statement or stored procedure to execute. The default value is an empty string ("").

Implements

IDbCommand.CommandText

Remarks

When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. The user may be required to use escape character syntax if the stored procedure name contains any special characters. The command executes this stored procedure when you call one of the Execute methods.

The .NET Framework Data Provider for Oracle does not support the question mark (?) placeholder for passing parameters to an SQL statement called by an OracleCommand of CommandType.Text. In this case, named parameters must be used. For example:

SELECT * FROM Customers WHERE CustomerID = :pCustomerID

When using named parameters in an SQL statement or stored procedure, you must precede the parameter name with a colon (:). However, when referring to a named parameter elsewhere in your code (for example, when calling Add), do not precede the named parameter with a colon (:). The .NET Framework Data Provider for Oracle supplies the colon automatically.

Example

[Visual Basic, C#, C++] The following example creates an OracleCommand and sets some of its properties.

[Visual Basic] 
Public Sub CreateMyOracleCommand()
    Dim myCommand As New OracleCommand()
    myCommand.CommandText = "SELECT * FROM Emp ORDER BY EmpNo"
    myCommand.CommandType = CommandType.Text
End Sub

[C#] 
public void CreateMyOracleCommand() 
{
   OracleCommand myCommand = new OracleCommand();
   myCommand.CommandText = "SELECT * FROM Emp ORDER BY EmpNo";
   myCommand.CommandType = CommandType.Text;
}

[C++] 
public:
 void CreateMyOracleCommand() 
 {
    OracleCommand* myCommand = new OracleCommand();
    myCommand->CommandText = S"SELECT * FROM Emp ORDER BY EmpNo";
    myCommand->CommandType = CommandType::Text;
 }

[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

OracleCommand Class | OracleCommand Members | System.Data.OracleClient Namespace | Connection | CommandType

Show:
© 2016 Microsoft