Data | database | statement
When using ASP to manipulate the database, many people use the recordset, but I feel better with the SQL statement, so I wrote this article, I hope it will help you.
<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following paragraphs are connected to the database and disconnected (the database is in Access format and is connected by DSN)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Connect ()
dsn= "Filedsn=acces.dsn" ' Dacces.dsn as a DSN for MDB files, set up when you configure ODBC, and if you want to upload files, you can upload the access.dsn together.
Set Cnn=server.createobject ("ADODB. Connection ")" Create ADO Objects
Cnn.open DSN Open DSN file in current directory (DSN is DSN for Access file)
Response.Write "Database connection succeeded:" & cnn.state & "<br>"
Cnn.close ' Close connection
Response.Write "Database is closed" & cnn.state & "<br>"
Set cnn=nothing ' Clears variables
End Sub
'. ' "" "" "" "" "" "" "" "" "" "" "' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Sub sel ()
dsn= ' Filedsn=acces.dsn ' DACCES.DSN is the DSN
Set Cnn=server.createobject ("ADODB") for the MDB file. Connection ") ' Creates an ADO object
Cnn.open DSN opens the DSN file in the current directory (DSN for Access file)
' and gets the result
sql= ' select * from user ' Constructs the SQL statement
set RS=CNN. Execute (SQL) ' Send SQL
' one loop to output all the records in the recordset
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 paragraph is manipulating the database (modifying the content)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Modi ()
dsn= "Filedsn=acces.dsn" ' Dacces.dsn as a DSN for an MDB file
Set Cnn=server.createobject ("ADODB. Connection ")" Create ADO Objects
Cnn.open DSN Open DSN file in current directory (DSN is DSN for Access file)
sql= "Update user set Name= ' This is the program ' where Name= ' A '" ' constructs modify SQL statements
Cnn. Execute SQL ' send out SQL
Cnn.close
Set cnn=nothing
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following paragraph is manipulating the database (deleting content)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Del ()
dsn= "Filedsn=acces.dsn" ' Dacces.dsn as a DSN for an MDB file
Set Cnn=server.createobject ("ADODB. Connection ")" Create ADO Objects
Cnn.open DSN Open DSN file in current directory (DSN is DSN for Access file)
Sql= "Delete from user where name= ' B '" ' Construct deletes SQL statement
Cnn. Execute SQL ' send out SQL
Cnn.close
Set cnn=nothing
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following paragraph is manipulating the database (add content)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Add ()
dsn= "Filedsn=acces.dsn" ' Dacces.dsn as a DSN for an MDB file
Set Cnn=server.createobject ("ADODB. Connection ")" Create ADO Objects
Cnn.open DSN Open DSN file in current directory (DSN is DSN for Access file)
' sql= ' insert into user (Name,sex,note) VALUES (' TT ', ' TT ', ' TT ') ' Constructs add SQL statements
' CNN. Execute SQL ' send out SQL
Cnn.close
Set cnn=nothing
End Sub
%>