<%
Dim Db,connstr,conn,sql,rs
' Database file name
db = "Test.mdb"
' Database connection string
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (DB)
' Create an instance of the connection connection object
Set conn = Server.CreateObject ("ADODB. Connection ")
' Call the Open method of Conn to turn on the connection
Conn.Open ConnStr
' SQL statement tb_user as table name
' Modify sql = ' UPDATE tb_user Set username= ' test1 ' where userid=1 '
' Remove sql = ' Delete from Tb_user where userid=1 '
' Add sql = ' INSERT into Tb_user (username,sex) VALUES (' test1 ', ' female ') "
Sql= "Select username from tb_user where userid=1" ' Query
' Create an object instance of the Adodb.recordset data record RS
Set rs = Server.CreateObject ("ADODB". Recordset ")
' Execute SQL statement to get recordset
Rs. Open sql,conn,1,1
' Determine if there is data, there is output, no hint
If not Rs. EOF Then
Response.Write (RS ("username"))
Else
Response.Write ("no user")
%>
Ps:
Set rs = Server.CreateObject ("Adodb.recordset")
Rs.Open Sql,conn
Can be replaced with the
Set Rs=conn.execute (SQL)
Same effect
ASP connection database and simple crud