Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Function

Status
Not open for further replies.

xxLewisxx

Technical User
Apr 7, 2004
23
0
0
GB
Hi all,

I've got the following (asp) code for a search function but it doesn't seem to be linking to the database (Access).

I've tested it wiht names that definately exist within the database but it's not retuning any records.

This is the form the user has to fill out:

<Form method=post action=searchemployees.asp>
<p class=intro>Employee Surname:</p>
<p class=links>
<input type="text" name="StaffSurname">
<br>
<input type="submit" value="Search">
</form>

And this is the asp page it links to:

<%@ Language=VBScript %>
<html>

<link rel="stylesheet" type="text/css" href="stylesheet.css">

<head>
<title>EmployeeSearch</title>
</head>
<body>

<p class=heading>Employee Details</p>

%>

<%


set conn = Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"

surName = Request.QueryString("StaffSurname")

Call conn.Open(Server.Mappath("FinalProject.mdb"))
strSql="SELECT StaffID FROM TblStaff WHERE StaffSurname = '" & surName & "';"

Set rs = Conn.Execute(strSql)

if rs.eof Then
Response.write("No records Returned")
end if

do until rs.eof
Response.write(rs("StaffID"))
rs.movenext
loop

Conn.Close
%>

Any ideas?

Thanks,

Lx
 
Try this:

surName = Request.Form("StaffSurname")

And also see what Response.Write strSql looks like.

Thanks

VJ
 
Cheers!!

I got it working.

Thanks for the suggestion

Lucy.
 
Also, I would change this:

if rs.eof Then
Response.write("No records Returned")
end if

do until rs.eof
Response.write(rs("StaffID"))
rs.movenext
loop

to this:

Code:
if rs.eof Then
   Response.write("No records Returned")
[b]else[/b]

   do until rs.eof
       Response.write(rs("StaffID"))
       rs.movenext
   loop
end if

You don't want to hit the loop if you already know there are no records
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top