Adding records to a database with command objects and Recordset objects which is better _asp base

Source: Internet
Author: User
Adding records to a database with command objects and Recordset objects which is better?
Which one should I choose?

command is used for parameter passing, especially for batch parameter passing. The command object is mainly to pass arguments to SQL statements, Storedprocude,
Rely on the power of SQL to complete the operation of the database, and the Recordset object, we can be seen as encapsulating the data object and providing a series of
Methods and properties to simplify the programming of the database.
We can see from the following two methods to add a record to the database demo, the two objects in dealing with some problems on the different methods used:
The Recordset object seems to be better understood, but command has a better performance, especially in the case of batch join records.
First, use the Command object method:
Const ADCMDTEXT=&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};D bq=" & _
Server.MapPath ("/source_asp") & "/property/chunfeng.mdb";
Comm. Activeconnection=conn
Comm.commandtype=adcmdtext
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

Second, the method of using the Recordset object
Const ADCMDTABLE=&H0002
Set Conn=server.createobject ("ADODB. Connection ")
Set Rs=server.createobject ("ADODB. RecordSet ")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};D bq=" & _
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.