Differences between rs.openand conn.exe cute in ASP

Source: Internet
Author: User

Rs. open SQL, conn: If the SQL statement is delete, update, or insert, a closed record set is returned. Do not set an rs during use. close and write rs at the end of the file. close
Multiple Record Sets rs1.open sql1 And conn can be used in the middle. The last record set is rs. close rs1.close.
Conn.exe cute (SQL) if the SQL statement is delete, update, and insert, a closed record set is returned. Do not use rs. close at the end of the file before writing rs. close.
Multiple Record Sets rs1.open sql1 And conn can be used in the middle. The last record set is rs. close rs1.close.
If SQL is update,insert,delete, you should use conn.execute( SQL # number conn.exe cute SQL
If the SQL statement is a select statement, set rs1_conn.exe cute (SQL) must be used in parentheses and cannot be omitted. This is because vbscript features, with the return value
The call must be enclosed in parentheses. Call without return values can be left in parentheses.

Note: whether it is rs. open SQL, connis also conn.exe cute (SQL) [here the SQL is delete, update, insert], a closed record set will be returned after execution.
That is to say, if SQL statements are insert, update, or delete statements, then RS in set rs1_conn.exe cute (SQL) makes no sense.

1.conn.exe cute
SQL = "select * from admin where username = 'xiaozhu '"
Set rsw.conn.exe cute (SQL)
The record set is automatically disabled after execution.
You only need to close the connection.
Conn. close
Set conn = nothing

2. rs. open
Set rs = server. createobject ("adodb. recordset ")
SQL = "select * from admin where username = 'xiaozhu '"
Rs. open SQL, conn, 1, 1
You can set some parameters, that is, the locking and cursor moving methods.
Close the record set and connection.
Rs. close
Set rs = nothing
Conn. close
Set conn = nothing

3.command.exe cute
SQL = "select * from admin where username = 'xiaozhu '"
Set rs1_command.exe cute (SQL)

**************************************** *************************************
1.
Set rs1_conn.exe cute ("if it is a select statement") to obtain rs. recordcount =-1
Rs. open SQL, And conn ("SQL is select statement"). rs. recordcount is the normal number of records.

2.
Rs. open is to open the database conn.exe cute is to execute SQL commands
Set rs1_conn.exe cute (insert, update, delete) returns a closed record set
Set rs1_conn.exe cute (select) returns a record set that is not closed

3.
CONN. EXECUTE (SQL, RowsAffected, C)
Parameter description:
The SQL value can be an SQL statement, table name, stored procedure name, or any string accepted by the data provider. To improve performance, it is best to specify a proper value for the C parameter.
The optional parameter RowsAffected returns the number of values affected after the INSERT, UPDATE, or DELETE statement is executed. These queries return a closed Recordset object.
A SELECT query returns an open Recordset with a RowsAffected value of-1 and one or more rows.
4.
Conn.exe cute SQL is suitable for use when a recordset object is not returned, for example, the following code:
SQL = "delete from enews where id =" & cstr (id)
Conn.exe cute SQL

To return A recordset object, use the following code:
SQL = "select from enews where id =" & cstr (id)
Set rs = conn.exe cute (SQL)

If the parentheses (set rs = conn.exe cute SQL) in execute (SQL) are removed, an error message such as "the statement is not over" is displayed. I have reviewed the syntax format, two formats are found, which are described as follows:
Format 1: Connection object name. Execute (SQL command ).
Format 2: Connection object name. Execute (data table name ).

From the preceding format, we can see that the SQL commands after execute are included in brackets, but in fact, if you do not need to include the SQL commands in brackets for deletion or modification operations, you can also execute them correctly, why? When executing a query, the SQL command must be included in the brackets. Otherwise, an error occurs. After reading all the ASP tutorials at hand, I did not mention this problem. I did not find any answer after searching, ask the predecessors to give me some advice on the reasons, but not just about the syntax rules. I hope to get the correct answer. Thank you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.