The difference between Rs.Open and Conn.execute in ASP-application techniques

Source: Internet
Author: User
Rs.Open sql,conn: If SQL is Delete,update,insert, it will return a closed recordset, do not have a rs.close to write at the end of the file Rs.close
Multiple recordsets Rs1.open sql1,conn in the middle, and the last to close the recordset: Rs.close rs1.close
Conn.execute (SQL) If SQL is Delete,update,insert, it returns a closed recordset, not a rs.close in the end of the file Rs.close
In the middle can be more than one recordset Rs1.open Sql1,conn, the last piece closed Recordset: Rs.close rs1.close.
If SQL is update,insert,delete, you should either use Conn.execute (SQL) or do not have parentheses Conn.execute sql
If SQL is a SELECT statement, you should use the set Rs=conn.execute (SQL) bracket to make sure that you cannot omit it: this is because of the nature of VBScript, with the return value
Calls must be parentheses, and calls without return values can not be parentheses.


Note: either Rs.Open sql,conn or Conn.execute (SQL) [This SQL is Delete,update,insert] will return a closed recordset after execution
In other words, if SQL is an INSERT, update, or DELETE statement, then RS in set Rs=conn.execute (SQL) is meaningless.

1.conn.execute
Sql= "SELECT * from admin where username= ' Xiaozhu '"
Set Rs=conn.execute (SQL)
Automatically close the recordset after execution
The last thing you need to do is 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, locking and how the cursor moves
Finally, to turn off recordsets and connections
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing

3.command.execute
Sql= "SELECT * from admin where username= ' Xiaozhu '"
Set Rs=command.execute (SQL)

*****************************************************************************
1.
Rs.recordcount=-1 obtained by set Rs=conn.execute ("If it is a SELECT statement")
Rs.Open sql,conn ("SQL for SELECT statement") Rs.recordcount as normal number of records

2.
Rs.Open is open database conn.execute is execute SQL instruction
Set Rs=conn.execute (Insert,update,delete) returns a closed set of records
Set Rs=conn.execute (SELECT) returns a recordset that is not closed

3.
CONN. EXECUTE (SQL,ROWSAFFECTED,C)
Parameter meaning:
The SQL value can be either an SQL statement, a table name, a stored procedure name, or any string that the data provider can accept. In order to improve performance, it is best to specify the appropriate value for the C parameter
The optional parameter rowsaffected returns the number of effects after the insert, UPDATE, or delete query execution. These queries return a closed Recordset object.
A select query returns a rowsaffected value of 1 and returns an open Recordset with one or more rows of content.
4.
Conn.execute SQL is suitable for use when you do not need to return a Recordset object, such as the following code:
Sql= "Delete from enews where id=" &cstr (ID)
Conn.execute SQL

If you need to return the Recordset object, use the following code:
Sql= "Select from enews where id=" &cstr (ID)
Set rs = conn.execute (SQL)

If you remove the parentheses here (that is, set rs = Conn.execute sql), you will be prompted with the "statement does not end" error prompts, I looked at the grammar format, found that there are two types of formats, detailed as follows:
Format One: Connection object name. Execute (SQL instruction).
Format Two: Connection object name. Execute (data table name).

As you can see from the format above, the SQL instructions that follow execute are enclosed in parentheses, but in fact, if you do not need to include the SQL instructions in parentheses to perform the deletion or modification, why? To execute a query, you must include the SQL instructions in parentheses, otherwise will be wrong, see all the ASP tutorials on hand did not mention this problem, search for a pass also did not find the answer, I implore predecessors to give guidance on the reasons, can not just say the grammatical rules on this yo, 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.