OracleCommand.CommandType 属性

定义

获取或设置一个指示如何解释 CommandText 属性的值。

public:
 property System::Data::CommandType CommandType { System::Data::CommandType get(); void set(System::Data::CommandType value); };
public:
 virtual property System::Data::CommandType CommandType { System::Data::CommandType get(); void set(System::Data::CommandType value); };
public System.Data.CommandType CommandType { get; set; }
public override System.Data.CommandType CommandType { get; set; }
member this.CommandType : System.Data.CommandType with get, set
Public Property CommandType As CommandType
Public Overrides Property CommandType As CommandType

属性值

CommandType 值之一。 默认值为 Text

实现

例外

该值不是有效的 CommandType

示例

以下示例创建派生类 OracleCommand 的实例并设置其某些属性。

public void CreateOracleCommand()
{
   OracleCommand command = new OracleCommand();
   command.CommandText = "SELECT * FROM Emp ORDER BY EmpNo";
   command.CommandType = CommandType.Text;
}
Public Sub CreateOracleCommand()
    Dim command As New OracleCommand()
    command.CommandText = "SELECT * FROM Emp ORDER BY EmpNo"
    command.CommandType = CommandType.Text
End Sub

注解

当 属性 CommandType 设置为 StoredProcedure时,应将 CommandText 属性设置为完整的 Oracle 调用语法。 然后,在调用 Execute 方法之一时,命令将执行此存储过程,例如 ExecuteReader (或 ExecuteNonQuery) 。

ConnectionCommandType如果当前连接正在执行执行或提取操作,则无法设置 和 CommandText 属性。

.NET Framework Data Provider for Oracle 不支持问号 (?) 占位符将参数传递给 由 OracleCommand 调用的 CommandType.TextSQL 语句。 在这种情况下,必须使用命名参数。 例如:

SELECT * FROM Customers WHERE CustomerID = :pCustomerID  

在 由 OracleCommandCommandType.Text的 调用的 SQL 语句中使用命名参数时,必须在参数名称前面加上冒号 (:) 。 但是,在存储过程中或引用代码中其他位置的命名参数时, (例如,在向属性) 添加 OracleParameter 对象 Parameters 时,不要在命名参数前面加上冒号 (:) 。 Oracle .NET Framework数据提供程序自动提供冒号。

适用于

另请参阅