andysargeant Posted April 18, 2006 Share Posted April 18, 2006 Hi,I'm trying to create a search form for an online database in order to enable users to search through a list of items.So far I have:<form name="frmSearch" action="foodlist.asp" method="post"><input name="txtSearchItem" type="text"><input type="submit" value="Search"><% Const cs = "..."Dim rsDim txtSearchItemtxtSearchItem = Request.Form("txtSearchItem")Set rs = CreateObject("ADODB.Recordset")rs.Open "SELECT*FROM [Food] WHERE [itemName] LIKE txtSearchItem", csDo Until rs.EOF Response.Write rs.Fields("ItemName").value rs.MoveNextLoopSet rs = Nothing%>I'm pretty sure it's just my syntax on my SQL, I just don't know how to put the variable "txtSearchItem" into the select query.Anyone got any suggestions??ThanksAndy Link to comment Share on other sites More sharing options...
pulpfiction Posted April 18, 2006 Share Posted April 18, 2006 Hi, Try this...sql statement:SELECT*FROM [Food] WHERE [itemName] LIKE '" & txtSearchItem & "'(that would be a single quotes on the outside and double quotes inside) Link to comment Share on other sites More sharing options...
andysargeant Posted April 18, 2006 Author Share Posted April 18, 2006 Hey,Thanks for your help. It works now, just had to put in some wildcards:'%" & txtSearchItem & "%'Cheers Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2006 Share Posted April 18, 2006 also put spaces on either side of * Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now