When using ASP to operate databases, many people use record sets, but I think it is better to use SQL statements, so I wrote this article, hoping to help you.
<%
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''
'The following sections are connected to the database and disconnected (the database is in Access format and uses DSN for connection)
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
Sub connect ()
Dsn = "FILEDSN = acces. dsn" 'dacces. dsn is the dsn of the mdb file. It is created when ODBC is configured. If you want to upload a file, you can upload access. dsn together.
Set cnn = server. createobject ("ADODB. Connection") 'creates an ADO object
Cnn. open dsn 'open the dsn file in the current directory (dsn is the access file's dsn)
Response. write "database connection successful:" & cnn. state & "<br>"
Cnn. close 'close the connection
Response. write "The database has been closed" & cnn. state & "<br>"
Set cnn = nothing 'clear the variable
End sub
'''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
'The following section describes how to manipulate a database (query content)
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Sub sel ()
Dsn = "FILEDSN = acces. dsn" 'dacces. dsn is the dsn of the mdb file
Set cnn = server. createobject ("ADODB. Connection") 'creates an ADO object
Cnn. open dsn 'open the dsn file in the current directory (dsn is the access file's dsn)
'Send the operation and get the result.
SQL = "select * from user" 'to construct an SQL statement
Set rs = cnn. Execute (SQL) 'sends an SQL statement
'One loop outputs all records in the record set
While not rs. eof
Values = rs ("name ")
Response. write values & "<br>"
Rs. movenext
Wend
Rs. close
Cnn. close
Set cnn = nothing
End sub
'''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
'The following section is about database manipulation (modification content)
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Sub modi ()
Dsn = "FILEDSN = acces. dsn" 'dacces. dsn is the dsn of the mdb file
Set cnn = server. createobject ("ADODB. Connection") 'creates an ADO object
Cnn. open dsn 'open the dsn file in the current directory (dsn is the access file's dsn)
SQL = "update user set name = 'this is the program 'Where name = 'a'" '.
Cnn. Execute SQL 'sends an SQL statement
Cnn. close
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.