OracleCommand Class

Definition

Warning

This API is now obsolete.

表示要对数据库执行的 SQL 语句或存储过程。Represents an SQL statement or stored procedure to execute against a database. 无法继承此类。This class cannot be inherited.

public ref class OracleCommand sealed : System::ComponentModel::Component, ICloneable, IDisposable, System::Data::IDbCommand
public ref class OracleCommand sealed : System::Data::Common::DbCommand, ICloneable
public sealed class OracleCommand : System.ComponentModel.Component, ICloneable, IDisposable, System.Data.IDbCommand
public sealed class OracleCommand : System.Data.Common.DbCommand, ICloneable
[System.Obsolete("OracleCommand has been deprecated. http://go.microsoft.com/fwlink/?LinkID=144260", false)]
public sealed class OracleCommand : System.Data.Common.DbCommand, ICloneable
type OracleCommand = class
    inherit Component
    interface ICloneable
    interface IDbCommand
    interface IDisposable
type OracleCommand = class
    inherit DbCommand
    interface ICloneable
Public NotInheritable Class OracleCommand
Inherits Component
Implements ICloneable, IDbCommand, IDisposable
Public NotInheritable Class OracleCommand
Inherits DbCommand
Implements ICloneable
Inheritance
Inheritance
Attributes
Implements

Examples

下面的示例使用 OracleCommandExecuteReader 方法连同 OracleDataReaderOracleConnection,从表中选择行。The following example uses the ExecuteReader method of OracleCommand, along with OracleDataReader and OracleConnection, to select rows from a table.

public void ReadMyData(string connectionString)
{
    string queryString = "SELECT EmpNo, DeptNo FROM Scott.Emp";
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString, connection);
        connection.Open();
        OracleDataReader reader = command.ExecuteReader();
        try
        {
            while (reader.Read())
            {
                Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetInt32(1));
            }
        }
        finally
        {
            // always call Close when done reading.
            reader.Close();
        }
    }
}
Public Sub ReadMyData(ByVal connectionString As String)
    Dim queryString As String = "SELECT EmpNo, DeptNo FROM Scott.Emp"
    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString, connection)
        connection.Open()
        Dim reader As OracleDataReader = command.ExecuteReader()
        Try
            While reader.Read()
                Console.WriteLine(reader.GetInt32(0) & ", " _
                   & reader.GetInt32(1))
            End While
        Finally
            ' always call Close when done reading.
            reader.Close()
        End Try
    End Using
End Sub

Remarks

此类型已弃用,并将在 .NET Framework 的未来版本中删除。This type is deprecated and will be removed in a future version of the .NET Framework. 有关详细信息,请参阅Oracle 和 ADO.NETFor more information, see Oracle and ADO.NET.

OracleCommand 类提供以下方法来针对数据源执行命令:The OracleCommand class provides the following methods for executing commands against a data source:

Item 说明Description
ExecuteReader 执行返回行的命令。Executes commands that return rows.
ExecuteOracleNonQuery 针对 Connection 执行 SQL 语句并返回受影响的行数。Executes an SQL statement against the Connection and returns the number of rows affected.
ExecuteNonQuery 执行 SQL INSERT、DELETE、UPDATE 和 SET 语句等命令。Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements.
ExecuteScalar 从数据库中检索单个值(例如聚合值)作为 .NET Framework 数据类型。Retrieves a single value (for example, an aggregate value) from a database as a .NET Framework data type.
ExecuteOracleScalar 从数据库中检索单个值(例如,聚合值)作为特定于 Oracle 的数据类型。Retrieves a single value (for example, an aggregate value) from a database as an Oracle-specific data type.

可以重置 CommandText 属性,并重新使用 OracleCommand 对象。You can reset the CommandText property and reuse the OracleCommand object.

如果执行命令导致严重 OracleException,则 OracleConnection 可能会关闭。If execution of the command results in a fatal OracleException, the OracleConnection may close. 但是,用户可以重新打开连接并继续操作。However, the user can reopen the connection and continue.

Note

与另一个 .NET Framework 数据提供程序(SQL Server、OLE DB 和 ODBC)中的命令对象不同,OracleCommand 对象不支持 CommandTimeout 属性。Unlike the Command object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), the OracleCommand object does not support a CommandTimeout property. 设置命令超时不起作用,返回的值始终为零。Setting a command timeout has no effect and the value returned is always zero.

Constructors

OracleCommand()

初始化 OracleCommand 的新实例。Initializes a new instance of the OracleCommand.

OracleCommand(String)

使用查询的文本初始化 OracleCommand 类的新实例。Initializes a new instance of the OracleCommand class with the text of the query.

OracleCommand(String, OracleConnection)

用查询文本和 OracleCommand 对象初始化 OracleConnection 类的新实例。Initializes a new instance of the OracleCommand class with the text of the query and an OracleConnection object.

OracleCommand(String, OracleConnection, OracleTransaction)

用查询文本、OracleCommand 对象以及 OracleConnection 初始化 OracleTransaction 类的新实例。Initializes a new instance of the OracleCommand class with the text of the query, an OracleConnection object, and an OracleTransaction.

Properties

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
CommandText

获取或设置针对数据库执行的 SQL 语句或存储过程。Gets or sets the SQL statement or stored procedure to execute against the database.

CommandTimeout

获取或设置在终止尝试执行命令并生成错误之前的等待时间(以秒为单位)。Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.

CommandType

获取或设置一个指示如何解释 CommandText 属性的值。Gets or sets a value indicating how the CommandText property is interpreted.

Connection

获取或设置 OracleCommand 的此实例使用的 OracleConnectionGets or sets the OracleConnection used by this instance of the OracleCommand.

Container

获取包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DbConnection

当在派生类中重写时,获取或设置此 DbCommand 使用的 DbConnectionWhen overridden in a derived class, gets or sets the DbConnection used by this DbCommand.

(Inherited from DbCommand)
DbParameterCollection

在派生类中重写时,获取 DbParameter 对象的集合。When overridden in a derived class, gets the collection of DbParameter objects.

(Inherited from DbCommand)
DbTransaction

当在派生类中重写时,获取或设置执行 DbCommand 对象时所在的 DbTransactionWhen overridden in a derived class, gets or sets the DbTransaction within which this DbCommand object executes.

(Inherited from DbCommand)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
DesignTimeVisible

获取或设置一个值,该值指示此命令对象在自定义界面控件中是否可见。Gets or sets a value indicating whether the command object should be visible in a customized interface control.

Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Parameters

获取 OracleParameterCollectionGets the OracleParameterCollection.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Transaction

获取或设置要在其中执行 OracleTransactionOracleCommandGets or sets the OracleTransaction within which the OracleCommand executes.

UpdatedRowSource

获取或设置一个值,该值指定 Update 方法如何将命令结果应用到 DataRowGets or sets a value that specifies how the Update method should apply command results to the DataRow.

Methods

Cancel()

试图取消 OracleCommand 的执行。Attempts to cancel the execution of an OracleCommand.

Clone()

创建此 OracleCommand 对象的一个副本。Creates a copy of this OracleCommand object.

CreateDbParameter()

在派生类中重写时,创建 DbParameter 对象的新实例。When overridden in a derived class, creates a new instance of a DbParameter object.

(Inherited from DbCommand)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
CreateParameter()

创建 OracleParameter 对象的新实例。Creates a new instance of an OracleParameter object.

Dispose()

释放 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose() (Inherited from DbCommand)
Dispose(Boolean)

释放 Component 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Dispose(Boolean) (Inherited from DbCommand)
DisposeAsync()

异步处置命令对象。Asynchronously diposes the command object.

(Inherited from DbCommand)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExecuteDbDataReader(CommandBehavior)

当在派生类中重写时,针对连接执行命令文本。When overridden in a derived class, executes the command text against the connection.

(Inherited from DbCommand)
ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)

提供程序应执行该方法对 ExecuteReader 重载提供非默认的实现。Providers should implement this method to provide a non-default implementation for ExecuteReader overloads.

默认实现调用同步 ExecuteReader() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteReader() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteReader 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteReader will be communicated via the returned Task Exception property.

该方法可用于请求操作之前接受取消标记。This method accepts a cancellation token that can be used to request the operation to be cancelled early. 实现可能会忽略该请求。Implementations may ignore this request.

(Inherited from DbCommand)
ExecuteNonQuery()

针对 Connection 执行 SQL 语句并返回受影响的行数。Executes an SQL statement against the Connection and returns the number of rows affected.

ExecuteNonQueryAsync()

ExecuteNonQuery()的异步版本,针对一个连接对象执行一个 SQL 声明。An asynchronous version of ExecuteNonQuery(), which executes a SQL statement against a connection object.

通过 CancellationToken.None 调用 ExecuteNonQueryAsync(CancellationToken)Invokes ExecuteNonQueryAsync(CancellationToken) with CancellationToken.None.

(Inherited from DbCommand)
ExecuteNonQueryAsync(CancellationToken)

这是 ExecuteNonQuery() 的异步版本。This is the asynchronous version of ExecuteNonQuery(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteNonQuery() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteNonQuery() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteNonQuery() 引发的异常将通过任务异常属性传递。Exceptions thrown by ExecuteNonQuery() will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

(Inherited from DbCommand)
ExecuteOracleNonQuery(OracleString)

针对 Connection 执行 SQL 语句并返回受影响的行数。Executes an SQL statement against the Connection and returns the number of rows affected.

ExecuteOracleScalar()

执行查询,并将查询返回的结果集中第一行的第一列作为 Oracle 特定的数据类型返回。Executes the query, and returns the first column of the first row in the result set returned by the query as an Oracle-specific data type. 忽略其他列或行。Extra columns or rows are ignored.

ExecuteReader()

CommandText 发送到 Connection 并生成一个 OracleDataReaderSends the CommandText to the Connection and builds an OracleDataReader.

ExecuteReader(CommandBehavior)

CommandText 发送到 Connection,并使用 CommandBehavior 值之一构造 OracleDataReaderSends the CommandText to the Connection, and builds an OracleDataReader using one of the CommandBehavior values.

ExecuteReaderAsync()

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader.

通过 CancellationToken.None 调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken) with CancellationToken.None.

(Inherited from DbCommand)
ExecuteReaderAsync(CancellationToken)

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader. 此方法传播有关应取消操作的通知。This method propagates a notification that operations should be canceled.

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

(Inherited from DbCommand)
ExecuteReaderAsync(CommandBehavior)

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader.

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

(Inherited from DbCommand)
ExecuteReaderAsync(CommandBehavior, CancellationToken)

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

(Inherited from DbCommand)
ExecuteScalar()

执行查询,并将查询返回的结果集中第一行的第一列作为 .NET Framework 数据类型返回。Executes the query, and returns the first column of the first row in the result set returned by the query as a .NET Framework data type. 忽略其他列或行。Extra columns or rows are ignored.

ExecuteScalarAsync()

ExecuteScalar() 的异步版本,执行查询,并将查询返回的结果集中第一行的第一列返回。An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. 所有其他的列和行将被忽略。All other columns and rows are ignored.

通过 CancellationToken.None 调用 ExecuteScalarAsync(CancellationToken)Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

(Inherited from DbCommand)
ExecuteScalarAsync(CancellationToken)

这是 ExecuteScalar() 的异步版本。This is the asynchronous version of ExecuteScalar(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteScalar() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteScalar() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteScalar 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

(Inherited from DbCommand)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Prepare()

在数据源中创建命令的准备好的(即已编译的)版本。Creates a prepared (or compiled) version of the command at the data source.

PrepareAsync(CancellationToken)

在数据源上异步创建准备就绪(或已编译)的命令版本。Asynchronously creates a prepared (or compiled) version of the command on the data source.

(Inherited from DbCommand)
ResetCommandTimeout()

CommandTimeout 属性重置为默认值。Resets the CommandTimeout property to the default value.

ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(Inherited from Component)

Events

Disposed

在通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Explicit Interface Implementations

IDbCommand.Connection

获取或设置 IDbCommand 的此实例使用的 IDbConnectionGets or sets the IDbConnection used by this instance of the IDbCommand.

(Inherited from DbCommand)
IDbCommand.CreateParameter()

创建 IDbDataParameter 对象的新实例。Creates a new instance of an IDbDataParameter object.

IDbCommand.CreateParameter()

创建 IDbDataParameter 对象的新实例。Creates a new instance of an IDbDataParameter object.

(Inherited from DbCommand)
IDbCommand.ExecuteReader()

Connection 执行 CommandText 并生成 IDataReaderExecutes the CommandText against the Connection and builds an IDataReader.

IDbCommand.ExecuteReader()

Connection 执行 CommandText 并生成 IDataReaderExecutes the CommandText against the Connection and builds an IDataReader.

(Inherited from DbCommand)
IDbCommand.ExecuteReader(CommandBehavior)

针对 CommandText 执行 Connection,并使用 IDataReader 值之一生成 CommandBehaviorExecutes the CommandText against the Connection, and builds an IDataReader by using one of the CommandBehavior values.

IDbCommand.ExecuteReader(CommandBehavior)

Connection 执行 CommandText,并使用 CommandBehavior 值之一生成 IDataReaderExecutes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.

(Inherited from DbCommand)
IDbCommand.Parameters

获取 IDataParameterCollectionGets the IDataParameterCollection.

(Inherited from DbCommand)
IDbCommand.Transaction

获取或设置将在其中执行此 DbCommand 对象的 DbTransactionGets or sets the DbTransaction within which this DbCommand object executes.

(Inherited from DbCommand)

Applies to

See also