Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in SQL search of populated dropdown box 1

Status
Not open for further replies.

KingElvis

Programmer
Jan 28, 2004
39
0
0
IL
Guys, please help a beginner! I can't find where I'm going wrong. I have the following dropdown box:


<select name="mLast" size="1" tabindex="8">
<option selected>Any Speaker</option>
<%=SF_GetSpeakerSELECT(Request.Form("mLast"))%>
</select>

This is populated by the following code:

<%Function SF_GetSpeakerSELECT(ByVal intCurrentSpeaker)

Dim rsData, strHTML, strSQL
strHTML = ""
If (intCurrentSpeaker <> "") AND IsNumeric(intCurrentSpeaker) Then
intCurrentSpeaker = cInt(intCurrentSpeaker)
End If

strSQL = "SELECT DISTINCT mLast From shiur"
Call DAL_GetRS(strSQL, rsData)

If Not (rsData is Nothing) Then
If rsData.State=1 Then
rsData.MoveFirst

While NOT rsData.EOF

strHTML = strHTML & "<OPTION>" & rsData("mLast") & "</OPTION>"

rsData.MoveNext
Wend

End If
End If

If strHTML = "" Then
strHTML = "<OPTION>Unavailable</OPTION>"
End If

SF_GetSpeakerSELECT = strHTML

SET rsData = Nothing

End Function
%>

However, I get an error when performing the following SQL search:

<%
If Request.Form(mLast) <> "Any Speaker" Then
strSQL = strSQL & " AND mLast = "& Request.Form("mLast")
End If
%>


The error message reads:

Expecting string input
/search.asp, line 254
The function expects a string as input.


 
It appears that you're missing double-quotes around mLast in your comparison.
Code:
If Request.Form(mLast) <> "Any Speaker" Then
should be
Code:
If Request.Form("mLast") <> "Any Speaker" Then
I don't think there's a string value in a variable named mLast at that point, anyway, with the code you posted.
 
and ...

if you are entering a string into a sql query:

<%
If Request.Form(mLast) <> "Any Speaker" Then
strSQL = strSQL & " AND mLast = '"& Request.Form("mLast") & "'"
End If
%>
 
Simonchristieis, this is about the 4th time you've helped me out! I owe you one!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top