ASP common database connection and operation method and skill

Source: Internet
Author: User
Tags expression insert access database

1.ASP connect to an Access database

<%
dim conn,mdbfile
mdbfile=server.mappath("数据库名称.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=数据库密码;dbq="&mdbfile
%>

2. asp and SQL database connection:

<%
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服务器名称或IP地址;UID=sa;PWD=数据库密码;DATABASE=数据库名称
%>

To set up a Recordset object:

Set rs=server.createobject("adodb.recordset")
rs.open SQL语句,conn,3,2

3. SQL Common Command use method:

(1) Data record filtering:

Sql= "SELECT * from data table where field name = field value order By field name"

Sql= "SELECT * from data table where field name like '% field value ' Order By field name '

Sql= "SELECT top * from data table where field name order By field name"

Sql= "SELECT * from data table where field name in (' Value 1 ', ' Value 2 ', ' Value 3 ')"

Sql= "SELECT * from data table where field name between value 1 and value 2"

(2) Update data records:

sql= "Update data table set field name = field value where Condition expression"

Sql= Update data Table set field 1= value 1, field 2= value 2 ... field n= value n Where Condition expression "

(3) Delete data records:

Sql= "Delete from data table where condition expression"

Sql= "Delete from data table" (delete all records from datasheet)

(4) Adding data records:

sql= INSERT into Data table (field 1, Field 2, Field 3 ...) valuess (value 1, value 2, value 3 ...)

Sql= INSERT INTO Target datasheet SELECT * from source datasheet (add a record from the source datasheet to the destination datasheet)

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.