OracleCommand OracleCommand OracleCommand OracleCommand Class

定义

警告

此 API 现已过时。

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

public ref class OracleCommand sealed : 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 DbCommand
    interface ICloneable
Public NotInheritable Class OracleCommand
Inherits DbCommand
Implements ICloneable
继承
属性
实现

示例

下面的示例使用ExecuteReader方法OracleCommand,连同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

注解

此类型已弃用,将.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.

备注

与不同命令对象中的其他.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.

构造函数

OracleCommand() OracleCommand() OracleCommand() OracleCommand()

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

OracleCommand(String) OracleCommand(String) OracleCommand(String) OracleCommand(String)

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

OracleCommand(String, OracleConnection) OracleCommand(String, OracleConnection) OracleCommand(String, OracleConnection) 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(String, OracleConnection, OracleTransaction) OracleCommand(String, OracleConnection, OracleTransaction) 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.

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

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

(Inherited from Component)
CommandText CommandText CommandText CommandText

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

CommandTimeout CommandTimeout CommandTimeout CommandTimeout

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

CommandType CommandType CommandType CommandType

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

Connection Connection Connection Connection

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

Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

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

(Inherited from Component)
DesignTimeVisible DesignTimeVisible DesignTimeVisible DesignTimeVisible

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

Events Events Events Events

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

(Inherited from Component)
Parameters Parameters Parameters Parameters

获取 OracleParameterCollectionGets the OracleParameterCollection.

Site Site Site Site

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

(Inherited from Component)
Transaction Transaction Transaction Transaction

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

UpdatedRowSource UpdatedRowSource UpdatedRowSource UpdatedRowSource

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

方法

Cancel() Cancel() Cancel() Cancel()

尝试取消执行 OracleCommandAttempts to cancel the execution of an OracleCommand.

Clone() Clone() Clone() Clone()

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

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) 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() CreateParameter() CreateParameter() CreateParameter()

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

Dispose() Dispose() Dispose() Dispose()

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

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

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
ExecuteNonQuery() ExecuteNonQuery() ExecuteNonQuery() ExecuteNonQuery()

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

ExecuteOracleNonQuery(OracleString) ExecuteOracleNonQuery(OracleString) ExecuteOracleNonQuery(OracleString) ExecuteOracleNonQuery(OracleString)

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

ExecuteOracleScalar() ExecuteOracleScalar() ExecuteOracleScalar() 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() ExecuteReader() ExecuteReader() ExecuteReader()

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

ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior)

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

ExecuteScalar() ExecuteScalar() ExecuteScalar() 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.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

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

(Inherited from Component)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
Prepare() Prepare() Prepare() Prepare()

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

ResetCommandTimeout() ResetCommandTimeout() ResetCommandTimeout() ResetCommandTimeout()

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

ToString() ToString() ToString() ToString()

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

(Inherited from Component)

显式界面实现

IDbCommand.CreateParameter() IDbCommand.CreateParameter() IDbCommand.CreateParameter() IDbCommand.CreateParameter()

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

IDbCommand.ExecuteReader() IDbCommand.ExecuteReader() IDbCommand.ExecuteReader() IDbCommand.ExecuteReader()

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

IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior)

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

事件

Disposed Disposed Disposed Disposed

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

(Inherited from Component)

适用于

另请参阅