A simple ASP Site search Instance source code

Source: Internet
Author: User

<%
Dim database,conn,connstr
database= "Example.mdb" Database tutorial name
Set Conn=server.createobject ("Adodb.connection") ' Create Connection object
' Provider parameter sets the driver for the database, Access uses the OLE DB driver; The data source parameter sets the actual path and file name of the database
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (Database)
Conn.Open connstr ' Connect the database using the Open method
str= "ASP" keyword
Set Rs=server.createobject ("Adodb.recordset") ' Creates a Recordset object
' Query from the database for records containing STR in content
Sql= "SELECT * From example where content like '% ' &str& '% '"
Rs.Open sql,conn,1,3 ' Execute query, the result is saved in RS
If rs.eof or Rs.bof then ' does not exist record
Response.Write (' Alert (') does not contain a record for the keyword ASP! ')")
Response.End
Else
' Existence record
Response.Write "There is a:<br><br> in the database with a keyword ASP"
Do, not rs.eof ' loops show IDs for all records
%>
&LT;%=RS ("id")%> <%=rs ("content")%><br>
<%
Rs.movenext
Loop
End If
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>

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.