Basic ASP operations on databases

Source: Internet
Author: User

1. Add record

Method 1:Execute method of connection object

Set con = server. Createobject ("ADODB. Connection ")
Insertstr = "insert into Table Name (Field 1, Field 2,...) values (value1, value2,...) 'insert record SQL statement
Con. Open constr
Con. Execute (insertstr)
Con. Close
Set con = nothing
Bytes -------------------------------------------------------------------------------------------
Method 2:Addnew method of the recordset object

Set con = server. Createobject ("ADODB. Connection ")
Set rs = server. Createobject ("ADODB. recordset ")
Querystr = "select * from table name" 'query record SQL statement
Con. Open constr
Rs. Open querystr, Con, 1, 3

Rs. addnew
RS ("Field 1") = value1
RS ("Field 2") = value2
......
Rs. Update

Rs. Close
Set rs = nothing
Con. Close
Set con = nothing

 

Ii. query records

Set con = server. Createobject ("ADODB. Connection ")
Set rs = server. Createobject ("ADODB. recordset ")
Querystr = "select field from table name where..." 'query record SQL statement
Con. Open constr
Rs. Open querystr, Con, 1, 1

Do while not Rs. EOF do
'Read data
Variable 1 = RS ("Field 1 ")
Variable 2 = RS ("Field 2 ")
...
Loop

Rs. Close
Set rs = nothing
Con. Close
Set con = nothing

 3. Modify records

Method 1:Execute method of connection object

Set con = server. Createobject ("ADODB. Connection ")
Con. Open constr
Updatestr = "Update table name set field 1 = value1, Field 2 = value2 where id =..." 'update record SQL statement
Con. Execute (updatestr)
Con. Close
Set con = nothing
----------------------------------------------------------------------
Method 2:Update method of recordset object
 
Set con = server. Createobject ("ADODB. Connection ")
Set rs = server. Createobject ("ADODB. recordset ")
Querystr = "select field from table name where..." 'query record SQL statement
Con. Open constr
Rs. Open querystr, Con, 1, 3
RS ("Field 1") = value1
RS ("Field 2") = value2
...
Rs. Update

Rs. Close
Set rs = nothing
Con. Close
Set con = nothing

 

Iv. delete records

Set con = server. Createobject ("ADODB. Connection ")
Deletestr = "delete from table name where id =" & id' SQL statement for deleting records
Con. Open constr
Con. Execute (deletestr)
Con. Close
Set con = nothing

 

Related Article

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.