ADO Execute 方法
The Execute method executes a specified query, SQL statement, stored procedure, or provider-specific text.
Execute的作用是:執行一個查詢語句、陳述語句、程序或技術提供對象[provider]的詳細文本。
The results are stored in a new Recordset object if it is a row-returning query. A closed Recordset object will be returned if it is not a row-returning query.?
如果返回行[row-returning]查詢語句,那么結果將被存儲在一個新的記錄對象中;如果它不是一個返回行[row-returning]查詢語句,那么它將返回一個關閉的記錄對象。
Note: The returned Recordset is always a read-only, forward-only Recordset!
注意:返回的Recordset是一個只讀的、只向前兼容的Recordset。
Tip: To create a Recordset with more functionality, first create a Recordset object. Set the desired properties, and then use the Recordset object's Open method to execute the query.
提示:在第一次創建Recordset對象時,需要將它創建為一個更具功能性的Recordset對象。設置一個我們所希望的屬性,使用Recordset對象的Open方法去執行查詢語句。
Syntax for row-returning
row-returning[返回行]語法
| Set objrs=objconn.Execute(commandtext,ra,options) |
Syntax for non-row-returning
non-row-returning[非返回行]語法
| objconn.Execute commandtext,ra,options |
| commandtext | Required. The SQL statement, stored procedure, or provider-specific text to execute 必要參數。指定需要執行的SQL語句,現存的程序或技術提供對象[provider]的詳細文本 |
| ra | Optional. The number of records affected by the query 可選參數。返回查詢語句執行的記錄數 |
| options | Optional. Sets how the provider should evaluate the commandtext parameter. Can be one or more CommandTypeEnum or ExecuteOptionEnum values. Default is adCmdUnspecified 可選參數。設置技術提供對象[provider]應該如何評估CommandText屬性的功能。它可以是一個或多個CommandTypeEnum 或 ExecuteOptionEnum的值。默認值是adCmdUnspecified |
Example
案例
| <% sql="SELECT companyname FROM Customers" Set rs=conn.Execute(sql) %> |
?
CommandTypeEnum Values
?
?
| adCmdUnspecified | -1 | Does not specify the command type argument. 不指定指令類型自變量 |
| adCmdText | 1 | Evaluates CommandText as a textual definition of a command or stored procedure call. 指示提供者應該將Source作為命令的文本定義來計算。 |
| adCmdTable | 2 | Evaluates CommandText as a table name whose columns are all returned by an internally generated SQL query. 指示ADO生成SQL查詢以便從在Source中命名的表中返回所有行 |
| adCmdStoredProc | 4 | Evaluates CommandText as a stored procedure name. 將CommandText作為一個已存的程序名稱 |
| adCmdUnknown | 8 | Indicates that the type of command in the CommandText property is not known. 默認值。指定未知的CommandText屬性命令 |
| adCmdFile | 256 | Evaluates CommandText as the file name of a persistently stored Recordset. Used with Recordset.Open or Requery only. 指示應從在Source中命名的文件中恢復保留(保存的)Recordset。它僅能與Recordset.Open 或 Requery 指令一起使用 |
| adCmdTableDirect | 512 | Evaluates CommandText as a table name whose columns are all returned. Used with Recordset.Open or Requery only. To use the Seek method, the Recordset must be opened with adCmdTableDirect. This value cannot be combined with the ExecuteOptionEnum value adAsyncExecute. 指示提供者更改從在 Source 中命名的表中返回所有行/ 將CommandText作為一個表的名稱(該表的列全部是通過內部的SQL查詢語句返回的)。它僅適用Recordset.Open 或 Requery 指令;如果需要使用查找方式,那么Recordset必須以adCmdTableDirect打開。這個值不能與ExecuteOptionEnum值 adAsyncExecute一起使用 |
?
?
?
ExecuteOptionEnum Values
?
?
| adOptionUnspecified | -1 | Indicates that the command is unspecified. 指明為指定的指令 |
| adAsyncExecute | ? | Indicates that the command should execute asynchronously. This value cannot be combined with the CommandTypeEnum value adCmdTableDirect. 指明指令是否需要異步執行。這個值不能與CommandTypeEnum 之中的adCmdTableDirect一起使用 |
| adAsyncFetch | ? | Indicates that the remaining rows after the initial quantity specified in the CacheSize property should be retrieved asynchronously. 指明在CacheSize屬性中指定了初始量以后,是否應該異步獲取保留行[remaining rows] |
| adAsyncFetchNonBlocking | ? | Indicates that the main thread never blocks while retrieving. If the requested row has not been retrieved, the current row automatically moves to the end of the file. If you open a Recordset from a Stream containing a persistently stored Recordset, adAsyncFetchNonBlocking will not have an effect; the operation will be synchronous and blocking. adAsynchFetchNonBlocking has no effect when the adCmdTableDirect option is used to open the Recordset. |
| adExecuteNoRecords | ? | Indicates that the command text is a command or stored procedure that does not return rows (for example, a command that only inserts data). If any rows are retrieved, they are discarded and not returned. adExecuteNoRecords can only be passed as an optional parameter to the Command or Connection Execute method. 它僅指明了指令文本僅是一條不返回任何行的指令或現存程序(如:一條只執行數據插入的指令)。如果沒有任何行被提取,那么他們將放棄執行并不返回任何值。 adExecuteNoRecords僅可以作為一個可選參數傳遞到指令中或連接執行方法[Connection Execute method]中 |
| adExecuteStream | ? | Indicates that the results of a command execution should be returned as a stream. adExecuteStream can only be passed as an optional parameter to the Command Execute method. 指明需要以結果流的形式返回命令執行的結果。adExecuteStream僅可以作為一個可選參數傳遞到指令中或連接執行方法[Connection Execute method]中 |
| adExecuteRecord | ? | Indicates that the CommandText is a command or stored procedure that returns a single row which should be returned as a Record object. 指明CommandText僅是返回一個單獨行(該單獨行作為一條記錄對象返回)的一條指令或現存程序 |
總結
以上是生活随笔為你收集整理的ADO Execute 方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 保持图片和图片框一致的方法 收藏
- 下一篇: ASP中怎么实现SQL数据库备份、恢复!