Help with VBScript/Access database


Joined
May 3, 2017
Messages
1
Reaction score
0
I have an old Search script in VB and would like to display a message if the search item is not found in the database. Sounds simple, but I haven't been able to achieve it. Everything else has worked fine for years.

Any help would be greatly appreciated.

The code is as follows:

<form action="<%= strURL %>" method="get">
<input type="submit" name="submit" value="Search" class="success button postfix" />
<input name="search" value="<%= strSearch %>" class="mytext" />
</form></p>

<%
If strSearch <> "" Then
' MapPath of virtual database file path to a physical path.
strDBPath = Server.MapPath("../../db/plants.mdb")
' Create an ADO Connection to connect to the sample database.
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
' Build query based on the input.
strSQL = "SELECT plantname,image,description " _
& "FROM master " _
& "WHERE plantname LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR plantname LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY plantname;"
' Execute query using the connection object.
Set rstSearch = cnnSearch.Execute(strSQL)
%>

Display results:
<%
Do While Not rstSearch.EOF
%>
<div class="twelve columns border">
<div class="five columns"><img src="images/<%= rstSearch.Fields("image").Value %> " /> </div>
<div class="four columns"><p class="boldtext"><%= rstSearch.Fields("plantname").Value %></p></br><%= rstSearch.Fields("description").Value %> </div>
<div class="one columns boldtext"></div>
<div class="one columns boldtext"></div>
</div>

<%
rstSearch.MoveNext
Loop
%>

<%
' Close our recordset and connection and dispose of the objects
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End If
%>
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top