Table of contents
TOC
折叠目录
展开目录

Execute 方法 (ADO Connection)Execute Method (ADO Connection)

office 365 dev account|上次更新日期: 2018/4/3
|
1 参与者

适用于: Access 2013 | Access 2016Applies to: Access 2013 | Access 2016

本文在语法返回值参数备注In this articleSyntaxReturn ValueParametersRemarks

执行指定的查询、SQL 语句、存储过程或提供程序特定的文本。Executes the specified query, SQL statement, stored procedure, or provider-specific text.

语法Syntax

对于非行返回命令字符串:For a non-row-returning command string:

对于行返回命令字符串:For a row-returning command string:

返回值Return Value

返回 Recordset 对象引用。Returns a Recordset object reference.

参数Parameters

  • CommandTextCommandText

  • 一个字符串值,包含要执行的 SQL 语句、 存储的过程、 URL 或提供程序特定的文本。A String value that contains the SQL statement, stored procedure, a URL, or provider-specific text to execute.还可以使用表名称,但仅用于 SQL 敏感的提供程序。Optionally, table names can be used but only if the provider is SQL aware.例如,如果使用名称为"Customers"(客户)的表,则 ADO 将自动在前面加上标准的 SQL Select 语法,以构成"SELECT * FROM Customers"并将其作为 T-SQL 语句传递给提供程序。For example if a table name of "Customers" is used, ADO will automatically prepend the standard SQL Select syntax to form and pass "SELECT * FROM Customers" as a T-SQL statement to the provider.

  • RecordsAffectedRecordsAffected

  • 可选。Optional.操作所影响到的提供程序返回的记录数的长整型变量。A Long variable to which the provider returns the number of records that the operation affected.

  • OptionsOptions

  • 可选。Optional.Long值,该值指示提供程序应如何评估_CommandText_参数。A Long value that indicates how the provider should evaluate the CommandText argument.该参数可以是一个或多个CommandTypeEnumExecuteOptionEnum 值的位掩码。Can be a bitmask of one or moreCommandTypeEnum orExecuteOptionEnum values.

请注意 使用ExecuteOptionEnumadExecuteNoRecords若要提高性能,通过最小化内部处理。Note Use the ExecuteOptionEnum value adExecuteNoRecords to improve performance by minimizing internal processing.

不要使用adCmdFileadCmdTableDirectCommandTypeEnum值与执行Do not use the CommandTypeEnum values of adCmdFile or adCmdTableDirect with Execute.这些值只能用作 RecordsetOpenRequery 方法的选项。These values can only be used as options with theOpen andRequery methods of a Recordset.

说明Remarks

连接对象中使用Execute方法执行您传递给该方法在_CommandText_参数中指定的连接上的任何查询。Using the Execute method on aConnection object executes whatever query you pass to the method in the CommandText argument on the specified connection.如果_CommandText_参数指定返回行的查询,执行生成任何结果存储在一个新的记录集对象。If the CommandText argument specifies a row-returning query, any results that the execution generates are stored in a new Recordset object.如果命令不需要返回结果(如 SQL UPDATE 查询),那么,只要指定了选项 adExecuteNoRecords ,提供程序都将返回 Nothing ,否则 Execute 返回关闭的 RecordsetIf the command is not intended to return results (for example, an SQL UPDATE query) the provider returns Nothing as long as the option adExecuteNoRecords is specified; otherwise Execute returns a closed Recordset.

返回的记录集对象始终是只读、 只进游标。The returned Recordset object is always a read-only, forward-only cursor.如果需要具更多功能的 Recordset 对象,请首先创建一个带所需属性设置的 Recordset 对象,然后使用 Recordset 对象的Open 方法执行查询并返回所需的游标类型。If you need a Recordset object with more functionality, first create a Recordset object with the desired property settings, then use the Recordset object'sOpen method to execute the query and return the desired cursor type.

CommandText_参数的内容特定于提供程序,可以是标准的 SQL 语法或任何特殊的命令格式提供程序支持。The contents of the _CommandText argument are specific to the provider and can be standard SQL syntax or any special command format that the provider supports.

此操作结束后,将发布 ExecuteComplete 事件。An ExecuteComplete event will be issued when this operation concludes.

请注意 使用 http 方案的 Url 将自动调用Microsoft OLE DB 提供程序的互联网发布Note URLs using the http scheme will automatically invoke the Microsoft OLE DB Provider for Internet Publishing.有关详细信息,请参阅绝对 URL 和相对 URLFor more information, see Absolute and Relative URLs.

访问支持资源ACCESS SUPPORT RESOURCES
访问 MSDN 上的开发人员论坛Access for developers forum on MSDN
访问 support.office.com 上的帮助Access help on support.office.com
访问 answers.microsoft.com 上的帮助Access help on answers.microsoft.com
在必应上搜索特定的访问错误代码Search for specific Access error codes on Bing
访问 UtterAccess 上的论坛Access forums on UtterAccess
访问 UtterAcess 上的 wikiAccess wiki on UtterAcess
访问开发人员和 VBA 编程帮助中心 (FMS)Access developer and VBA programming help center (FMS)
访问 StackOverflow 上的帖子Access posts on StackOverflow

© 2018 Microsoft