Which of the following is better to add a record to the database using the command object and recordset object?
Which one should I choose?
Command is used for parameter passing, especially for batch parameter passing. The command object mainly transmits parameters to SQL statements and storedprocude,
The powerful functions of SQL are used to perform database operations. The recordset object can be seen as a data object encapsulated and provides a series
To simplify the programming of the database.
We use the following two methods to add a record to the database:
The recordset object seems to be better understood, but the command performance is better, especially when records are added in batches.
1. Methods Using command objects:
Const ad1_text = & h0001
Const adinteger = 3
Const advarchar = 200
Const adparaminput = & h0001
Set conn = server. Createobject ("ADODB. Connection ")
Set comm = server. Createobject ("ADODB. Command ")
Conn. Open "driver = {Microsoft Access driver}; DBQ = "&_
Server. mappath ("/source_asp") & "/property/Chunfeng. mdb ;"
Comm. activeconnection = Conn
Comm. commandtype = ad1_text
Comm. commandtext = "insert into Chunfeng (ID, name ,)"&_
& "Values (?,?,?)"
Set Param = comm. createparameter ("ID", adinteger, adparaminput, 3,4)
Comm. Parameters. append Param
Set Param = comm. createparameter ("name", advarchar, adparaminput, 255, "Intels ")
Comm. Parameters. append Param
Comm. Execute
Conn. Close
2. Method of Using recordset object
const adcmdtable = & h0002
set conn = server. createobject ("ADODB. connection ")
set rs = server. createobject ("ADODB. recordset ")
Conn. open "driver = {Microsoft Access Driver (*. MDB)}; DBQ = "& _
server. mappath ("/source_asp") & "/property/Chunfeng. MDB; "
Rs. activeconnection = conn
Rs. open "Chunfeng", adcmdtable
Rs. addnew
RS ("ID") = 4
RS ("name") = "Intels"
Rs. update
Rs. close
Conn. close