Which of the following is better to add a record to the database using the command object and recordset object?

Source: Internet
Author: User

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

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.