OracleCommand 类

定义

警告

此 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. https://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
继承
属性
实现

示例

下面的示例使用 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

注解

此类型已弃用,并将在 .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 的新实例。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.

属性

CanRaiseEvents

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

(继承自 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

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

(继承自 Component)
DesignMode

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

(继承自 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.

(继承自 Component)
Parameters

获取 OracleParameterCollectionGets the OracleParameterCollection.

Site

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

(继承自 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.

方法

Cancel()

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

Clone()

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

CreateObjRef(Type)

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

(继承自 MarshalByRefObject)
CreateParameter()

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

Dispose()

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

(继承自 Component)
Dispose(Boolean)

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

(继承自 Component)
Equals(Object)

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

(继承自 Object)
ExecuteNonQuery()

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

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.

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

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

(继承自 Object)
GetLifetimeService()

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

(继承自 MarshalByRefObject)
GetService(Type)

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

(继承自 Component)
GetType()

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

(继承自 Object)
InitializeLifetimeService()

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

(继承自 MarshalByRefObject)
MemberwiseClone()

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

(继承自 Object)
MemberwiseClone(Boolean)

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

(继承自 MarshalByRefObject)
Prepare()

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

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.

(继承自 Component)

事件

Disposed

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

(继承自 Component)

显式界面实现

IDbCommand.CreateParameter()

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

IDbCommand.ExecuteReader()

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

IDbCommand.ExecuteReader(CommandBehavior)

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

适用于

另请参阅