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%>