We help IT Professionals succeed at work.

Wildcard search in ASP

dmoring
dmoring asked
on
I want to do record collection of a MSAccess db with a form with wildcard(s)possible in the form. What's the syntax for this?
Comment
Watch Question

I would just add it manually so you don't have to worry about it

<%
yourstring = "45"
if mid(yourstring,1,1)="0" then
  'don't worry about it
else
  yourstring = "0" & yourstring
end if
%>

If it's more complicated, I would let your database do all the work:

Select Whatever From TableName Where yournumber LIKE '_45' OR yournumber = '45'

Author

Commented:
Okay, but can you use a recordset to search for 'like' from to make a wild card search and what are the rules?
What do you mean rules?

<form method=post action = "thispage.asp">
Select text to seach for: <input type = "txtSearch">
<input type = "submit" value = "submit">



<%
set cn = server.createobject("ADODB.Connection")
cn.open yourDSN
set rs = cn.execute("select * from tablename where field like '%" & request.form("txtSearch") & "%'")
while not rs.eof
  response.write rs("fieldname") & "<BR>"
  rs.movenext
wend
%>

That will search strings, like if you enter CAT it will display things like

cats
catalog
dogcat
becatre

Author

Commented:
Got the answer from your own current question on minimizing 4.57 second searches...hope the points here will defray the cost of your other question (know you don't have enough!)
:-)

Thanks & Regards,
dmoring

Explore More ContentExplore courses, solutions, and other research materials related to this topic.