Whether it is rs.open sql, conn or conn.execute(sql) [SQL here is delete, update, insert] after execution, a closed record set will be returned. rs.open sql, conn: If sql is delete, update, insert A closed record set will be returned. During use, do not write rs.close and then write rs.close at the end of the file.
There can be multiple record sets rs1.open sql1,conn in the middle, and the last one closes the record set: rs.close rs1.close
conn.execute(sql) If sql is delete, update, or insert, it will return a closed record set. Do not use rs.close during use and write rs.close at the end of the file.
There can be multiple record sets in the middle: rs1.open sql1,conn, and the last one closes the record set: rs.close rs1.close.
If the sql is update, insert, delete, you should use conn.execute(sql) or you can omit the brackets conn.execute sql
If sql is a select statement, you should use set rs=conn.execute(sql). The brackets must be mandatory and cannot be omitted: this is because of the characteristics of vbscript, with return value
The call must be enclosed in parentheses, and the call without a return value does not need parentheses.
Note: Whether it is rs.open sql, conn or conn.execute(sql) [SQL here is delete, update, insert], a closed record set will be returned after execution.
In other words, if sql is an insert, update, or delete statement, then the RS in set rs=conn.execute(sql) has no meaning.
1.conn.execute
sql=select * from admin where username='xiaozhu'
set rs=conn.execute(sql)
Automatically close the record set after execution
Finally, you just 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 yourself, namely the locking and cursor movement methods.
Finally, close the recordset and connection
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.
set rs=conn.execute (if it is a select statement) gets rs.recordcount=-1
rs.open sql,conn (sql is a select statement) The rs.recordcount obtained is the normal number of records
2.
rs.open is to open the database conn.execute is to execute SQL instructions
set rs=conn.execute(insert,update,delete) returns a closed recordset
set rs=conn.execute(select) returns an unclosed recordset
3.
CONN.EXECUTE(SQL,RowsAffected,C)
Parameter meaning:
The value of SQL can be an SQL statement, table name, stored procedure name, or any string acceptable to the data provider. To improve performance, it is best to specify appropriate values for the C parameters
The optional parameter RowsAffected will return the number affected after the execution of the INSERT, UPDATE or DELETE query. These queries will return a closed Recordset object.
A SELECT query will return a RowsAffected value of -1 and return an open Recordset with one or more rows of content.
4.
conn.execute sql is suitable for use when there is no 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 a recordset object, use the following code:
sql=select from enews where id=&cstr(id)
set rs = conn.execute(sql)
If you remove the brackets here in execute(sql) (that is, set rs = conn.execute sql), an error message will be displayed such as the statement has not ended. I looked at the syntax format and found that there are two formats. The details are as follows:
Format 1: Connection object name.Execute (SQL command).
Format 2: Connection object name.Execute (data table name).
As can be seen from the above format, the sql instructions after execute are included in parentheses, but in fact, if you perform operations such as deletion or modification, you do not need to include the sql instructions in parentheses to execute them correctly. Why is this? To execute the query, you must include the sql command in parentheses, otherwise an error will occur. I have read all the ASP tutorials at hand and none of them mentioned this problem. I have searched and found no answer. Please give me some advice on the reason. Don't just talk about the grammar rules. I hope to get the correct answer, thank you.