ASP basic functions

Source: Internet
Author: User

ASP: Ado modify and delete database records
Time added: 2007-4-22
New database records
First, use ADO to connect to the ACCESS database ntopsamp. mdb, use the SQL command to open the "product" Record of the table, and pass the result back to the RS recordset. The ASP code is as follows:
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "DBQ =" & server. mappath ("ntopsamp. mdb") & "; driver = {Microsoft Access Driver (*. mdb )};"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "product", Conn, 1, 2
Use the addnew method to add a record. The ASP code is as follows:
Rs. addnew
You can use the following syntax to set the values of fields in a record table:
RS ("field name"). value = Value
RS ("field name") = Value
RS (field order) = Value
For example, the ASP code is as follows:
RS ("name"). value = "laptop"
RS ("quantity") = 100
RS (0) = "12345"
The last update method stores new records in the table.
Rs. Update
Rs. Close
Response. Write ("add record: Name = notebook ")

Modify database records
To modify the database records, use ADO to connect to the ACCESS database ntopsamp. mdb, run the SQL command to find the record to be modified, and pass the result back to the recordset of RS1. The ASP code is as follows:
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from product where name = 'laptop '"
Rs. Open SQL, Conn, 2, 2
If you find the record to be modified and set the values of each field in the table, the last update method will store the newly added record to the table. The ASP code is as follows:
If not Rs. EOF then
Randomize
No1 = round (RND () * 10)
New = "laptop-" & No1
RS ("name"). value = new
Rs. Update
Response. Write ("Modify record to: Name =" & RS1 ("name ")&"")
End if

Delete database records
To delete a database record, use ADO to connect to the ACCESS database ntopsamp. mdb, run the SQL command to find the record to be deleted, and pass the result back to the RS recordset. The ASP code is as follows:
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from product where name = '" & new1 &"'"
Rs. Open SQL, conn1, 1, 3
If you find the record to be deleted and use the next Delete method, you can delete the record in the table. The ASP code is as follows:
If not Rs. EOF then
Rs. Delete
Response. Write ("delete record: Name =" & new1)
End if
Conn. Close

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.