Dropdown from the database

J

J P Singh

Can Somone please tell me what is wrong with the following code.

It gives me a blank dropdown when there are values in the Currency Table and
it also does not display any form element that I place after this code.

Please help

Thanks

<select size="1" name="Currency" >
<%
SQL = "Select CurrSymbol FROM Currency "
SET RS = CONN_STRING.Execute(SQL)
While NOT RS.EOF%>
<option value="<%=RS("CurrSymbol")%>"><%=RS("CurrSymbol")%></option>
<%
RS.MoveNext
WEND
Set RS = NOTHING
%>
</select>
 
B

Bob Barrows

J said:
Can Somone please tell me what is wrong with the following code.

It gives me a blank dropdown when there are values in the Currency
Table and it also does not display any form element that I place
after this code.

Please help

Thanks

<select size="1" name="Currency" >
<%
SQL = "Select CurrSymbol FROM Currency "
SET RS = CONN_STRING.Execute(SQL)
While NOT RS.EOF%>
<option
value="<%=RS("CurrSymbol")%>"><%=RS("CurrSymbol")%></option> <%
RS.MoveNext
WEND
Set RS = NOTHING
%>
</select>

Do you have an "on error resume next" masking any errors? If so, comment it
out so you can see what the error is.

I suspect you will see a syntax error due to your use of a reserved keyword
for the name of your table. "Currency" is the name of a Jet datatype and
therefore the word should not be used for ahy object names. Here is the list
of reserved keywords: http://www.aspfaq.com/show.asp?id=2080

If you cannot change the name of the table for some reason, then you will
need to remember to surround it with brackets [] when you use it in queries.
If at all possible, you should change the name of this table.

Personally, I prefer this approach:

<select size="1" name="Currency" >
<%
SQL="Select '<option value=""' & CurrSymbol & '"">' & CurrSymbol" &_
& " & '</option>' FROM [Currency]"
'Response.Write SQL
SET RS = CONN_STRING.Execute(SQL)
If RS.EOF Then
Response.Write "<option value=0>No symbols returned</option>"
else
Response.Write RS.GetString
end if
RS.close:set RS = nothing
CONN_STRING.close: set CONN_STRING=nothing
%>
</select>

HTH,
Bob Barrows
 
S

Sylvain Lafontaine

Also, from the fact that it does not display any form element after, it's
possible that some of your CurrSymbol is a reserved caracter in HTML. If
so, then you should use Server.HTMLEncode (...) for both of your
RS("CurrSymbol").

It not a bad idea to look at the source code of the generated HTML page.

S. L.

Bob Barrows said:
J said:
Can Somone please tell me what is wrong with the following code.

It gives me a blank dropdown when there are values in the Currency
Table and it also does not display any form element that I place
after this code.

Please help

Thanks

<select size="1" name="Currency" >
<%
SQL = "Select CurrSymbol FROM Currency "
SET RS = CONN_STRING.Execute(SQL)
While NOT RS.EOF%>
<option
value="<%=RS("CurrSymbol")%>"><%=RS("CurrSymbol")%></option> <%
RS.MoveNext
WEND
Set RS = NOTHING
%>
</select>

Do you have an "on error resume next" masking any errors? If so, comment it
out so you can see what the error is.

I suspect you will see a syntax error due to your use of a reserved keyword
for the name of your table. "Currency" is the name of a Jet datatype and
therefore the word should not be used for ahy object names. Here is the list
of reserved keywords: http://www.aspfaq.com/show.asp?id=2080

If you cannot change the name of the table for some reason, then you will
need to remember to surround it with brackets [] when you use it in queries.
If at all possible, you should change the name of this table.

Personally, I prefer this approach:

<select size="1" name="Currency" >
<%
SQL="Select '<option value=""' & CurrSymbol & '"">' & CurrSymbol" &_
& " & '</option>' FROM [Currency]"
'Response.Write SQL
SET RS = CONN_STRING.Execute(SQL)
If RS.EOF Then
Response.Write "<option value=0>No symbols returned</option>"
else
Response.Write RS.GetString
end if
RS.close:set RS = nothing
CONN_STRING.close: set CONN_STRING=nothing
%>
</select>

HTH,
Bob Barrows


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
B

Bob Barrows

Sylvain said:
Also, from the fact that it does not display any form element after,
it's possible that some of your CurrSymbol is a reserved caracter in
HTML. If so, then you should use Server.HTMLEncode (...) for both of
your RS("CurrSymbol").
Yes, I should have thought of that. Good catch.

Bob Barrows
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top