Generally, a record set can be used.
Set rsw.conn.exe cute (SQL) or directly rsw.conn.exe cute (SQL)
And set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 0, 1, or Rs. Open SQL, Conn
In this case, open is usually a little better than the previous one.
(The command object is more flexible and the execution scope is wider)
Use conn.exe cute to directly execute the next set rs1_conn.exe cute (SQL)
It takes about 2 ~ 5 times !! (This is 1000 times in MSSQL loop), so before executing the next rsw.conn.exe cute !! Be sure to close it!
Rs. Open of a single object must be disabled before opening the next record set. Otherwise, an error occurs. The speed is basically the same in the case of SQL, Conn, 0, 1.
Therefore, set a Createobject ("ADODB. recordser ")
The last set rs = nothing reaches the end!
Open provides a lot of attributes for flexible operation of database metadata !!
In many cases, open is not required!
Conn.exe cute is very simple !!!
For example:
Rs1.open sql1, Conn, 0, 1
Rs. Open SQL, Conn, 1, 3
If RS (0) <0 then RS (0) = 0
RS (1) = aaa
RS (2) = bbb
Rs. Update' update record set written to database
Rs. addnew' adds a new record.
RS (0) = 1
RS (1) = ddd
RS (2) = KKK
Rs. Update
Id = RS (3) RS (s) 'the field is automatically numbered to get the automatic ID of the new record immediately // This is very common
Rs1.addnew new record for adding a connection to RS1 using ID rs
RS1 ("ID" = ID
RS1 (1) =...
..
Rs1.update
Rs1.close: Set RS1 = nothing
Rs. Close: Set rs = nothing
For specific operations, if conn.exe cute is used, four conn.exe cute
Conn.exe cute ("Update .."
Conn.exe cute ("insert into Table 1 :"
Rsw.conn.exe cute ("select new automatic ID"
Conn.exe cute ("insert into Table 2"
That method is logically organized and clear at a glance
There is also an interesting way to use recordset open record !!
Set rs = server. Createobject ("ADODB. recordset"
Set rs = server. Createobject ("ADODB. recordset"
Rs. Open sql1, Conn
Rs. Open sql2, Conn
This is to set two objects with the same name at the same time to open two record sets, and it is available!
'As long as the retrieved column name conforms to the metadata of these two sets of records
'Operation is normal !!
Extended
Set rs = server. Createobject ("ADODB. recordset"
Set rs = server. Createobject ("ADODB. recordset"
Set rs = server. Createobject ("ADODB. recordset"
Set rs = server. Createobject ("ADODB. recordset"
Rs. Open sql1, Conn
Rs. Open sql2, Conn
Rs. Open sql3, Conn
Rs. Open sql4, Conn
I have not tried more than two Rs with the same name !!
It seems a bit similar to querying with SQL and then opening the record set ~~~
If you only need to touch the database with one stroke, execute
If you want to perform complex operations on the database! Rs. Open is recommended.
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 applicable when you do not need to return a recordset object. For exampleCode:
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 ).