ConnectionThe object uses the Open Method to open the connection, eliminating the need to use the commectionstring attribute.
Syntax:
ConnectionObject. Open
Connectionstring, userid, password, openoptions
Where:
· Connection object refers to the instance of the connection object defined for you;
· Connectionstring is optional and contains information about the connected database;
· Userid: optional, including the user name for establishing the connection;
· Password is optional and includes the user password for establishing a connection;
· Openoptions is optional. If it is set to adconnectasync, the connection will be opened asynchronously.
RecordsetThe open method of the object is used to open tables in the database.
There are two ways to open: one is to use the record set open method, the other is to use the connection object execute method.
(A) Open Method of record set
Syntax:
Recordset.Open Source, ActiveConnection, CursorType,
LockType, Options
Where:
· Recordset is the instance of the defined record set object.
· Source option, indicating the source information of the opened record. it can be a legal command, object variable name, SQL statement, table name, stored procedure call, or file name that saves the record set.
· Activeconnection: Optional. The variable name of a valid connection object or a string containing the connectionstring parameter.
· Cursortype can be used to determine the pointer type used to open record set objects.
· Locktype Option
Determine the lock type used to open record set objects.
(B) Execute method of the connection object
Syntax:
Set
recordset=Connection.Execute(CommandText,RecordsAffected,Options)
Parameter description:
· Commandtext
Returns the SQL command, table name, stored procedure, or specified text to be executed.
· Recordsaffected
Optional. Value of the long type. The number of records affected by the operation is returned.
· Options: optional, long type value, indicating how to handle the commandtext parameter.
After opening two objects, a series of operations are performed on the record. Take the query operation of the command object as an example.
CommandThe syntax of the execute method of the object is as follows:
Command.Execute RecordsAffected, Parameters, Options
'Record set not returned
Or set
Rscordset = cmsad. Execute (recordsaffected, parameters, options) 'returns the record set
Commandtext Syntax:
Command.CommandText=stringvariable
Where:
Stringvariable is a string variable that contains SQL statements, table names, or stored procedures.