把文本框的值傳進(jìn)來,然后利用SQL語句中的like模糊查詢。如 sql="select * from news where title like '%"&request("title")&"%'"樓主在查詢的時(shí)候還要注意過濾空格和單引號(hào)等。下面這文章是介紹ASP做查詢功能,樓主可以看一下。詳見: 面是庫中URLINDEX表:URL和Keywords字段分別添加了索引.URL 文本 (索引:有(無重復(fù)))Title 文本Description 文本Summary 文本Keywords 文本(索引:有(無重復(fù)))<HTML><HEAD><TITLE>簡(jiǎn)單搜索引擎</TITLE></HEAD><BODY BGCOLOR=#ffffff MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN=0 TOPMARGIN=0><FORM METHOD="post" ACTION=" p?act=search">Query: <INPUT TYPE="Text" NAME="QueryString"><BR><INPUT TYPE="Submit" VALUE="Submit"></FORM></CENTER><%dim actact=request("act")if(act="search") thenQueryString = rm( "QueryString" )QueryWords = Split( QueryString )strIndent = " "' 如果搜索為空則返回If QueryString = "" ThenResponse.Redirect( " p" )End IfSession.timeout = 2If IsObject(Session("sitesearch_conn")) ThenSet conn = Session("sitesearch_conn")ElseSet conn = Server.CreateObject("ADODB.Connection")conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("database/ b"),"",""Set Session("sitesearch_conn") = connEnd If' 查詢語句sql = "SELECT * FROM [URLIndex] WHERE"'搜索Description字段sql = sql & " ( [Description] LIKE '%" & QueryWords( 0 ) & "%'" ' FirstFor i = LBound( QueryWords ) + 1 to UBound( QueryWords )If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" ThenIf uCase( QueryWords( i-1 ) ) = "OR" Thensql = sql & " OR [Description] LIKE '%" & QueryWords( i ) & "%'"Elsesql = sql & " AND [Description] LIKE '%" & QueryWords( i ) & "%'"End IfEnd IfNext' 搜索Keywords字段 sql = sql & " ) OR ( [Keywords] LIKE '%" & QueryWords( 0 ) & "%'"For i = LBound( QueryWords ) + 1 to UBound( QueryWords )If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" ThenIf uCase( QueryWords( i-1 ) ) = "OR" Thensql = sql & " OR [Keywords] LIKE '%" & QueryWords( i ) & "%'"Elsesql = sql & " AND [Keywords] LIKE '%" & QueryWords( i ) & "%'"End IfEnd IfNext' 搜索Title字段 sql = sql & " ) OR ( [Title] LIKE '%" & QueryWords( 0 ) & "%'"For i = LBound( QueryWords ) + 1 to UBound( QueryWords )If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" ThenIf uCase( QueryWords( i-1 ) ) = "OR" Thensql = sql & " OR [Title] LIKE '%" & QueryWords( i ) & "%'"Elsesql = sql & " AND [Title] LIKE '%" & QueryWords( i ) & "%'"End IfEnd IfNext' 搜索Summary字段 sql = sql & " ) OR ( [Summary] LIKE '%" & QueryWords( 0 ) & "%'"For i = LBound( QueryWords ) + 1 to UBound( QueryWords )If QueryWords( i ) <> "" and UCase( QueryWords(i) ) <> "OR" and UCase( QueryWords(i) ) <> "AND" ThenIf uCase( QueryWords( i-1 ) ) = "OR" Thensql = sql & " OR [Summary] LIKE '%" & QueryWords( i ) & "%'"Elsesql = sql & " AND [Summary] LIKE '%" & QueryWords( i ) & "%'"End IfEnd IfNextsql = sql & " )"Set rs = Server.CreateObject("ADODB.Recordset")rs.Open sql, conn, 3, 3 Response.Write "<BR><B> 你搜索的是: </B> " & QueryString Response.Write "<BR><B> 搜索的關(guān)鍵字: </B> "For i = LBound( QueryWords ) to UBound( QueryWords )Response.Write "<BR>" & strIndent & i & ": " & QueryWords( i )Next' Print the SQL StringResponse.Write "<BR><B> sql 語句 : </B> " & sql' Print the ResultsResponse.Write "<BR><B> 結(jié)果 : </B> <UL>"On Error Resume Nextrs.MoveFirstDo While Not rs.eofResponse.Write "<BR>" & "<A HREF=' p?IndexURL=" & rs.Fields("URL").Value & "'>" & rs.Fields("Title") & "</A> - " Response.Write rs.Fields("Description") & "<BR>"Response.Write " <FONT SIZE=2>URL: " & rs.Fields("URL") & "</FONT>"Response.Write "<HR SIZE=1 WIDTH=200 ALIGN=LEFT>"rs.MoveNextLoopResponse.Write "</UL>"end if %></BODY></HTML>