Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - searching MS Access DB on webpage
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

searching MS Access DB on webpage

 Post Reply Post Reply
Author
todd_uk View Drop Down
Newbie
Newbie


Joined: 14 March 2009
Location: UK
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote todd_uk Quote  Post ReplyReply Direct Link To This Post Topic: searching MS Access DB on webpage
    Posted: 14 March 2009 at 7:46pm
Hi All,
 
I'm trying to do a really simple thing in ASP - but forgot how!!
 
I have a database with a field called "name" that I want to search.  
 
I have my first page which the user ijnputs the search term e.g. "Thomas",  then when u click submit passes the value to the nex page, whicjh I want to display a list summary all records with the name "Thomas" e.g. <ID NO><Name><address>.
 
The next bit needs to be clever - so that when i Click on the ID number of the person - a full pop-up of that entire persons record appears?
 
Is this possible? 
 
Any hel would be ace!
 
Thanks,
T
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2009 at 7:55pm
You could try reading the ASP Tutorials on this website:

http://www.webwiz.net/kb/asp_tutorials/default.asp
S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
todd_uk View Drop Down
Newbie
Newbie


Joined: 14 March 2009
Location: UK
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote todd_uk Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2009 at 8:18pm

OK - searchvalue is what I have passed from the previous form.  I think i've balls'd up my SQL statement?  As that appears in text on this page -so if I submit value "jones" I get the state\ent printed as....."SELECT * FROM data WHERE detail LIKE 'jones%'"

The table is called "data" and field is called "name".  My primarky Key is callled ID_Num.
 
Any ideas would be ace ........... its been like 5 years since i've done ASP ol>
 
<%@ Language=vbscript %> 
<% option explicit %> 
<% 
Dim MyConn, SQL, oRs, srchval, srchval2, strConn, javalink, rColour, srchcriteria, Counter
 
srchval = Replace(Request.Form("searchvalue"), "'", "''") 
Set MyConn=Server.CreateObject("ADODB.Connection") 
MyConn.Provider="Microsoft.Jet.OLEDB.4.0" 
'local drive contains a version of the database
strConn= Server.MapPath("fileplan.mdb") 
MyConn.Open strConn 
   
'Get Surname and Christain Name(s) (optional)
SQL = "SELECT * FROM data WHERE name LIKE '"&srchval&"%'"
Response.Write SQL
Response.End

set oRs=MyConn.Execute(SQL) 
%> 
 
<html> 
<head> 
<title>Record Serach Results</title> 
<SCRIPT language="JavaScript">  
<!-- 
function openwin(thelink) 

window.open(thelink,'Details','width=650,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,re sizable=yes'); 
//-->  
</SCRIPT> 
<%
if oRs.EOF <> true then
Counter = 0  'Set the number of records read to zeo
%>
 <H2>Number of records found
  
<table border="0" cellpadding="5">
  <tr><th>
      <p>ID_No:
    <th>
      <p>Name
    <th>
      <p>Address
    <th>
      <p>Birthday
    <th>
      <p>Notes
      <p>
        <%
 
 rColour = "#D6D6D6"     'set the first line to grey or gray
 if oRs.EOF <> true then       'and srchval <> "" then
 ' if it not EOF and the two boxes not empty then read and write
 do   
     
 javalink = "javascript:openwin('details.asp?IDNum="& oRs("ID_No") &"')"
 
  Response.Write "<tr bgcolor='" & rColour &"'><td><p align=center><a href='#' onclick="&javalink&">" _
   & oRs("ID_No") & "</a>"
   
  Response.Write    "<td><p align=center>" & oRs("name") _ 
       & "<td><p align=center>" & oRs("address") _
   & "<td><p align=center>" & oRs("birthday")  _
   & "<td><p align=center>" & oRs("notes") 
     
 oRs.MoveNext 
 
 if (rColour="#D6D6D6") then   'first line gray 84 other
    rColour="#FFFFFF"   'lines white
 else 
    rColour="#D6D6D6" 
 end if  'end if rColour =  
   Counter = Counter + 1  'count the number of records
 loop until oRs.EOF      'loop until end of file
 else
  
 end if  'end if oRs.EOF <> true
else
 Response.Write "NO RECORDS FOUND CONTAINING THIS SEARCH ITEM"
end if 'end if of writing files to table
Response.Write"<tr><p></p>"  ' write up the number of records found
Response.Write"<H2>"&Counter&"<H2>" ' with the search item
%>
    </table> 
<FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> </FORM>
</html> 
<% 
 
'Tidy things up, free up memory by closing the connection object
oRs.Close 
MyConn.Close 
Set oRs = Nothing 
Set MyConn = Nothing 
%> 

 
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2009 at 9:13pm
<%@ Language=vbscript %> 
<% option explicit %>
<%
Dim MyConn, SQL, oRs, srchval, srchval2, strConn, javalink, rColour, srchcriteria, Counter
 
srchval = Replace(Request.Form("searchvalue"), "'", "''")
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Provider="Microsoft.Jet.OLEDB.4.0"
'local drive contains a version of the database
strConn= Server.MapPath("fileplan.mdb")
MyConn.Open strConn
  
'Get Surname and Christain Name(s) (optional)
SQL = "SELECT * FROM data WHERE name LIKE '"&srchval&"%'"
Response.Write SQL
Response.End


set oRs=MyConn.Execute(SQL)
%> 

S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
todd_uk View Drop Down
Newbie
Newbie


Joined: 14 March 2009
Location: UK
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote todd_uk Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2009 at 11:07pm
Grrrrrrrrrrrr.  It keeps givingme this below error?
 
The page is posting the variable through........... the database is connected, the table is called 'data' and the field is called 'detail'.  Please somebody tell me what i'm mmissing......

Technical Information (for support personnel)

  • Error Type:
    Microsoft VBScript compilation (0x800A0409)
    Unterminated string constant
    /searchdb.asp, line 20, column 58
    SQL = "SELECT * FROM data WHERE detail LIKE '"&srchval&"%'
    ---------------------------------------------------------^
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 15 March 2009 at 11:48am
Did you get trigger happy with the delete key?

There's no issues with the code you originally posted, but the error is saying that you haven't closed the string off, make sure there is a " (quote) at the end of the SQL statement line.

the line should look like this:

SQL = "SELECT * FROM data WHERE name LIKE '"&srchval&"%'"

S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.