The application of Access database in ASP

Source: Internet
Author: User
Tags sql query access database
access| Data | database

I am a professional computer software development, according to my summary: feel that each language development can not be separated from the application of the database, for learning programming focus on the application of the database and flexible programming ideas. The following I tell you about the ASP language Access database connection and several operations:

Connection to the database:
<%
Datafile= "Data.mdb"
Set Rs=server.createobject ("Adodb.connection")
conn= "Driver={microsoft Access DRIVER (*.mdb)}; Data source= "& Server.MapPath (" "& DataFile &")
Rs.Open Conn
%>

Add Data:
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "Select*from tablename" ' TableName as the name of the table in the data
Rs.Open sql,conn,1,1
Rs.addnew
RS ("data1") = "New1"
RS ("data2") = "New2"
RS ("data3") = "NEW3"
......
RS ("Datan") = "newn"
Rs.update
Rs.close
Conn.close
Set rs=nothing
Set sql=nothing
%>

Delete data:
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "Select*from tablename where Del=del" ' Second del for the data you want to delete
Rs.Open sql,conn,1,1
If rs.eof and Rs.bof then
Response.Write "Data does not exist"
Else
Rs.delete
Response.Write "Data has been deleted"
End If
%>

Data query:
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "Select*from tablename where Data=data" "The second del for the data you want to query, but also for multiple, with", "number separate
Rs.Open sql,conn,1,1
If rs.eof and Rs.bof then
Response.Write "Data does not exist"
Else
Rs.delete
Response.Write RS ("data") ' If there are multiple identical data, this can be used for ... next loop statement
End If
%>

Data display:
<%
Set Rs=server.createobject ("Adodb.recordset")
Sql= "Select*from tablename"
Rs.Open sql,conn,1,1
If rs.eof and Rs.bof then
Response.Write "No Data in database"
Else
While not rs.eof
Response.Write rs ("Data1")
Response.Write rs ("Data2")
Response.Write rs ("Data3")
......
Response.Write rs ("Datan")
Rs.movenext
Wend
End If%>



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.