PDA

View Full Version : Searching a Database using ASP


kasim
06-19-2003, 06:06 AM
Hi All. I am creating a website linked to a database. Functionality is adding, deleting, viewing, searching but for weeks now I have become stuck on the search page. I have completed add, and display that fully work. The search function consists of 2 pages. One is a html document and the other ASP. In the html document the user specifies the search criteria and then the ASP page is supposed to do the search which isn’t working much to my frustration! Please Please Please cam someone help me with this code. Many Thanks!

search.htm

<title>Search Log</title>
<form action="searchsubmit.asp" method="POST">
<select name="txtField">
<option value="Analyst_Name">Analyst Name</option>
<option value="Task_No">Task No</option>
</select>
<input type="Text" name="txtSearch" size="20"><p>
<input type="Submit" name="Submit" value="Search">
</form>


searchsubmit.asp

<%@ Language="VBScript"%>
<% Option Explicit %>
<!-- #include file='DBConnection.asp'-->
<%
dim rs
dim con
dim sql

Set con = GetADOConnection()

sql = "SELECT * FROM ServReqLog Where " & request.form("txtField") & " LIKE '%%" & request.form("txtSearch") & "%%';"
set rs = con.Execute(sql)
%>

<HTML>

<HEAD>
<TITLE>Search Results</TITLE>
</HEAD>

<BODY>
<font size="3" face="Arial">Search Results</font><hr>

<%
do while NOT rs.EOF
%>

<% If request.form("txtField")="Analyst_Name" then response.write rs("AnalystName") & "<br>"%>
<% If request.form("txtField")="Task_No" then response.write rs("TaskNo") & "<br>"%>
<hr width="200" align="left">

<%
CurrentRecordset.Movenext
loop
%>

</BODY>
</HTML>

jsawkang
06-19-2003, 07:46 AM
hi...

i don't know this work or not. just give it a try...

submitsearch.asp

Set con = GetADOConnection()

sql = "SELECT * FROM ServReqLog Where " & request.form("txtField") & " LIKE '%" & request.form("txtSearch") & "%'"
set rs = con.Execute(sql)

<%
while NOT rs.EOF
%>

<% If request.form("txtField")="Analyst_Name" then response.write rs("AnalystName") & "<br>"%>
<% If request.form("txtField")="Task_No" then response.write rs("TaskNo") & "<br>"%>
<hr width="200" align="left">

<%
rs.Movenext
wend
%>

NOTE: try check the sql query to see if "request.form("txtfield")" is in that query by using "response.write sql"

ansar
06-22-2003, 04:35 AM
this sql is simple one
try it
"select * from table where name like ' "&request("text1")&" % ' "

kasim
06-23-2003, 08:21 AM
Hi guys,

Thank you for your replies but unfortunately both solutions have not worked! After I have entered the name or the task number I click on "Submit" and it gives me the error:

"There is a problem with the page you are trying to reach and it cannot be displayed."

I think their is a problem with the ASP?? Can someone please help me. Thanks.

Kasim

OZN
07-08-2003, 07:48 AM
Try like this

SQL = "Select * From ServReqLog where txtField like '%" & Request.Form("txtSearch") & "%'"

kasim
07-08-2003, 01:24 PM
Thanks AZN and everyone else that replied but fortunately I have already fixed this problem several weeks ago. It was just a matter of changing the request.form to request.Form !!!

Really frustrating!

Thanks everyone once again! :D