<html>
<title>Test</title>
<body bgcolor="FFFFFF">
<%
sort = CStr(Request("sort"))
search = CStr(Request("search"))
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=asdf;Data Source=WIN-123"
Set rs = Server.CreateObject("ADODB.Recordset")
If sort = "ascending" Then
SQL = "select top 50 * from asdf order by Name"
ElseIf (search Is Not Nothing)
SQL = "select * from asdf WHERE name = '" & search & "'"
Else
SQL = "select top 50 * from asdf"
End If
rs.open SQL, conn
%>
<center><form acion="index.asp">
Search Name:<input name="search" /><input type="submit" value="Submit" />
</form></center>
I’m getting an error on my
Else If (search Is Not Nothing)
line, from what I can tell it should work. and of course I also cannot for some reason browse my site on my server to see what the actual error is.
Tested on my IIS 5, without
option explicit, when you useyour
searchhas been initialized tostring(VarType: 8).So even if
searchis “empty”, you can not useIsEmptyor similar function/statement to see if it’s empty. Usedirectly.
Also, remember to sanitize your SQL queries…