Still Not Resolved

Hi,
I want to display two fiels from a query in a combo box. I am checking to
make sure that the the selected fields do generate value. However, in the
combo box, I have only one field that is being displayed instead of two
fields. I would like to know whether this can be solved in the existing code?
Thanks

CODE:
<html>
<head>
<title>Populating two fields in combo box from a query</title>
</head>

<body>
<h2>
Populating two fields in combo box from a query</h2>

<%
Dim oConn
Dim oRS
Dim vCS
Dim sqltxt

set oConn=server.CreateObject("ADODB.connection")
vCS = "Provider=Microsoft.Jet.OLEDB.4.0"
vCS = vCS & "; Data Source=C:\Sailors.mdb"
oConn.connectionstring = vCS
oConn.Open

set oRS = server.CreateObject("ADODB.recordset")
sqltxt = "SELECT BoatName, BoatClass FROM Boats;"
oRS.Open sqltxt,oConn
Response.Write sqltxt & "<br>"
Response.Write oRS("BoatName") & "<br>"
Response.Write oRS("BoatClass") & "<br>"
'Response.End
%>
<select name="lstBoats" size="1">
<%
Do while not oRS.EOF
response.Write "<option value='" & oRS("BoatName") & "'>"
response.Write oRS("BoatClass") & "</option>"
oRS.MoveNext
Loop
%>
</select>
<%oRS.Close
Set oRS = nothing %>

<%'Response.Write "Hey You" & "<br>" %>
</body>
</html>
jack [ Mi, 22 August 2007 17:40 ] [ ID #1802332 ]

Re: Still Not Resolved

Jack wrote:
> Hi,
> I want to display two fiels from a query in a combo box. I am
> checking to make sure that the the selected fields do generate value.
> However, in the combo box, I have only one field that is being
> displayed instead of two fields. I would like to know whether this
> can be solved in the existing code? Thanks

Please show us the html that results from the code.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
reb01501 [ Mi, 22 August 2007 19:09 ] [ ID #1802334 ]

Re: Still Not Resolved

Bob,
Here is the output in html. Thanks
OUTPUT:

<html>
<head>
<title>Populating two fields in combo box from a query</title>
</head>

<body>
<h2>
Populating two fields in combo box from a query</h2>

SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
<select name="lstBoats" size="1">
<option value='A Sweet Song'>Laser</option><option
value='Blackbeard'>Laser</option><option value='No Excuse to
Lose'>Laser</option><option value='No Excuse Two Lose'>Laser</option><option
value='White Lightning'>Soling</option><option
value='Teal'>Soling</option><option value='TGV'>Soling</option><option
value='BB3'>Soling</option><option value='Nuts and
Bolts'>Soling</option><option value='Psycho'>Soling</option><option
value='Shasta'>Flying Scot</option><option value='Daphne'>Flying
Scot</option><option value='Red White and Blue'>Flying Scot</option>
</select>

</body>
</html>


"Bob Barrows [MVP]" wrote:

> Jack wrote:
> > Hi,
> > I want to display two fiels from a query in a combo box. I am
> > checking to make sure that the the selected fields do generate value.
> > However, in the combo box, I have only one field that is being
> > displayed instead of two fields. I would like to know whether this
> > can be solved in the existing code? Thanks
>
> Please show us the html that results from the code.
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>
jack [ Mi, 22 August 2007 20:18 ] [ ID #1802335 ]

Re: Still Not Resolved

If the data in Boats looks like this:
A Sweet Song | Laser
Blackbeard | Laser
No Excuse to Lose | Laser
No Excuse Two Lose | Laser
White Lightning | Soling
Teal | Soling
TGV | Soling
BB3 | Soling
Nuts and Bolts | Soling
Psycho | Soling
Shasta | Flying Scot
Daphne | Flying Scot
Red White and Blue | Flying Scot

Then that is the output I would expect from your code

What is wrong with it? What do you want it to look like?

Jack wrote:
> Bob,
> Here is the output in html. Thanks
> OUTPUT:
>
> <html>
> <head>
> <title>Populating two fields in combo box from a query</title>
> </head>
>
> <body>
> <h2>
> Populating two fields in combo box from a query</h2>
>
> SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
> <select name="lstBoats" size="1">
> <option value='A Sweet Song'>Laser</option><option
> value='Blackbeard'>Laser</option><option value='No Excuse to
> Lose'>Laser</option><option value='No Excuse Two
> Lose'>Laser</option><option value='White
> Lightning'>Soling</option><option value='Teal'>Soling</option><option
> value='TGV'>Soling</option><option value='BB3'>Soling</option><option
> value='Nuts and Bolts'>Soling</option><option
> value='Psycho'>Soling</option><option value='Shasta'>Flying
> Scot</option><option value='Daphne'>Flying Scot</option><option
> value='Red White and Blue'>Flying Scot</option> </select>
>
> </body>
> </html>
>

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
reb01501 [ Mi, 22 August 2007 20:36 ] [ ID #1802336 ]

Re: Still Not Resolved

Bob,
In my combo box, I am seeing only one field with the output as
Laser
Laser
Laser
Laser
Soling
Soling
Soling
Soling
Soling
Soling
Flying Scot
Flying Scot
Flying Scot
That's the problem I have. Do you think the size of the combo box needs to
be widened to accommodate the first field or what? Thanks.

"Bob Barrows [MVP]" wrote:

> If the data in Boats looks like this:
> A Sweet Song | Laser
> Blackbeard | Laser
> No Excuse to Lose | Laser
> No Excuse Two Lose | Laser
> White Lightning | Soling
> Teal | Soling
> TGV | Soling
> BB3 | Soling
> Nuts and Bolts | Soling
> Psycho | Soling
> Shasta | Flying Scot
> Daphne | Flying Scot
> Red White and Blue | Flying Scot
>
> Then that is the output I would expect from your code
>
> What is wrong with it? What do you want it to look like?
>
> Jack wrote:
> > Bob,
> > Here is the output in html. Thanks
> > OUTPUT:
> >
> > <html>
> > <head>
> > <title>Populating two fields in combo box from a query</title>
> > </head>
> >
> > <body>
> > <h2>
> > Populating two fields in combo box from a query</h2>
> >
> > SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
> > <select name="lstBoats" size="1">
> > <option value='A Sweet Song'>Laser</option><option
> > value='Blackbeard'>Laser</option><option value='No Excuse to
> > Lose'>Laser</option><option value='No Excuse Two
> > Lose'>Laser</option><option value='White
> > Lightning'>Soling</option><option value='Teal'>Soling</option><option
> > value='TGV'>Soling</option><option value='BB3'>Soling</option><option
> > value='Nuts and Bolts'>Soling</option><option
> > value='Psycho'>Soling</option><option value='Shasta'>Flying
> > Scot</option><option value='Daphne'>Flying Scot</option><option
> > value='Red White and Blue'>Flying Scot</option> </select>
> >
> > </body>
> > </html>
> >
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>
jack [ Mi, 22 August 2007 21:14 ] [ ID #1802337 ]

Re: Still Not Resolved

No, resizing won't do anything. The combo box (actually, it is called a
"dropdown", or, better yet, a "select" - there is no such combo box in
html) is displaying exactly what the html is telling it to display.

Look at one of the option tags:
<option value='A Sweet Song'>Laser</option>
It sounds as if you are expecting the content of the value attribute ("A
Sweet Song") to be displayed as well as the option tag's text ("Laser" -
the portion between the opening and closing tags). Sorry, it just does
not work that way. The dropdown will display whatever is in the text,
and only what is in the text. So you need to modify your code to make
the resulting html look the way you want it to look, probably via
concatenation. Start with straight html. Write small .htm a page
containing hard-coded html that gives you what you want. Then go back to
your code and modify it so that it results in the same html.


Jack wrote:
> Bob,
> In my combo box, I am seeing only one field with the output as
> Laser
> Laser
> Laser
> Laser
> Soling
> Soling
> Soling
> Soling
> Soling
> Soling
> Flying Scot
> Flying Scot
> Flying Scot
> That's the problem I have. Do you think the size of the combo box
> needs to be widened to accommodate the first field or what? Thanks.
>
> "Bob Barrows [MVP]" wrote:
>
>> If the data in Boats looks like this:
>> A Sweet Song | Laser
>> Blackbeard | Laser
>> No Excuse to Lose | Laser
>> No Excuse Two Lose | Laser
>> White Lightning | Soling
>> Teal | Soling
>> TGV | Soling
>> BB3 | Soling
>> Nuts and Bolts | Soling
>> Psycho | Soling
>> Shasta | Flying Scot
>> Daphne | Flying Scot
>> Red White and Blue | Flying Scot
>>
>> Then that is the output I would expect from your code
>>
>> What is wrong with it? What do you want it to look like?
>>
>> Jack wrote:
>>> Bob,
>>> Here is the output in html. Thanks
>>> OUTPUT:
>>>
>>> <html>
>>> <head>
>>> <title>Populating two fields in combo box from a query</title>
>>> </head>
>>>
>>> <body>
>>> <h2>
>>> Populating two fields in combo box from a query</h2>
>>>
>>> SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
>>> <select name="lstBoats" size="1">
>>> <option value='A Sweet Song'>Laser</option><option
>>> value='Blackbeard'>Laser</option><option value='No Excuse to
>>> Lose'>Laser</option><option value='No Excuse Two
>>> Lose'>Laser</option><option value='White
>>> Lightning'>Soling</option><option
>>> value='Teal'>Soling</option><option
>>> value='TGV'>Soling</option><option
>>> value='BB3'>Soling</option><option value='Nuts and
>>> Bolts'>Soling</option><option value='Psycho'>Soling</option><option
>>> value='Shasta'>Flying Scot</option><option value='Daphne'>Flying
>>> Scot</option><option value='Red White and Blue'>Flying
>>> Scot</option> </select>
>>>
>>> </body>
>>> </html>
>>>
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
reb01501 [ Mi, 22 August 2007 21:28 ] [ ID #1802338 ]

Re: Still Not Resolved

Thanks for the advise Bob. I appreciate it. I will try it. Thanks again.

"Bob Barrows [MVP]" wrote:

> No, resizing won't do anything. The combo box (actually, it is called a
> "dropdown", or, better yet, a "select" - there is no such combo box in
> html) is displaying exactly what the html is telling it to display.
>
> Look at one of the option tags:
> <option value='A Sweet Song'>Laser</option>
> It sounds as if you are expecting the content of the value attribute ("A
> Sweet Song") to be displayed as well as the option tag's text ("Laser" -
> the portion between the opening and closing tags). Sorry, it just does
> not work that way. The dropdown will display whatever is in the text,
> and only what is in the text. So you need to modify your code to make
> the resulting html look the way you want it to look, probably via
> concatenation. Start with straight html. Write small .htm a page
> containing hard-coded html that gives you what you want. Then go back to
> your code and modify it so that it results in the same html.
>
>
> Jack wrote:
> > Bob,
> > In my combo box, I am seeing only one field with the output as
> > Laser
> > Laser
> > Laser
> > Laser
> > Soling
> > Soling
> > Soling
> > Soling
> > Soling
> > Soling
> > Flying Scot
> > Flying Scot
> > Flying Scot
> > That's the problem I have. Do you think the size of the combo box
> > needs to be widened to accommodate the first field or what? Thanks.
> >
> > "Bob Barrows [MVP]" wrote:
> >
> >> If the data in Boats looks like this:
> >> A Sweet Song | Laser
> >> Blackbeard | Laser
> >> No Excuse to Lose | Laser
> >> No Excuse Two Lose | Laser
> >> White Lightning | Soling
> >> Teal | Soling
> >> TGV | Soling
> >> BB3 | Soling
> >> Nuts and Bolts | Soling
> >> Psycho | Soling
> >> Shasta | Flying Scot
> >> Daphne | Flying Scot
> >> Red White and Blue | Flying Scot
> >>
> >> Then that is the output I would expect from your code
> >>
> >> What is wrong with it? What do you want it to look like?
> >>
> >> Jack wrote:
> >>> Bob,
> >>> Here is the output in html. Thanks
> >>> OUTPUT:
> >>>
> >>> <html>
> >>> <head>
> >>> <title>Populating two fields in combo box from a query</title>
> >>> </head>
> >>>
> >>> <body>
> >>> <h2>
> >>> Populating two fields in combo box from a query</h2>
> >>>
> >>> SELECT BoatName, BoatClass FROM Boats;<br>A Sweet Song<br>Laser<br>
> >>> <select name="lstBoats" size="1">
> >>> <option value='A Sweet Song'>Laser</option><option
> >>> value='Blackbeard'>Laser</option><option value='No Excuse to
> >>> Lose'>Laser</option><option value='No Excuse Two
> >>> Lose'>Laser</option><option value='White
> >>> Lightning'>Soling</option><option
> >>> value='Teal'>Soling</option><option
> >>> value='TGV'>Soling</option><option
> >>> value='BB3'>Soling</option><option value='Nuts and
> >>> Bolts'>Soling</option><option value='Psycho'>Soling</option><option
> >>> value='Shasta'>Flying Scot</option><option value='Daphne'>Flying
> >>> Scot</option><option value='Red White and Blue'>Flying
> >>> Scot</option> </select>
> >>>
> >>> </body>
> >>> </html>
> >>>
> >>
> >> --
> >> Microsoft MVP -- ASP/ASP.NET
> >> Please reply to the newsgroup. The email account listed in my From
> >> header is my spam trap, so I don't check it very often. You will get
> >> a quicker response by posting to the newsgroup.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>
jack [ Mi, 22 August 2007 21:38 ] [ ID #1802339 ]

Re: Still Not Resolved

On Aug 22, 9:28 pm, "Bob Barrows [MVP]" <reb01... [at] NOyahoo.SPAMcom>
wrote:

> Look at one of the option tags:
> <option value='A Sweet Song'>Laser</option>
> It sounds as if you are expecting the content of the value attribute ("A
> Sweet Song") to be displayed as well as the option tag's text ("Laser" -
> the portion between the opening and closing tags). Sorry, it just does
> not work that way. The dropdown will display whatever is in the text,
> and only what is in the text. So you need to modify your code to make
> the resulting html look the way you want it to look, probably via
> concatenation.

Something like:

Do while not oRS.EOF
response.Write "<option value='" & oRS("BoatName") & "'>"
response.Write oRS("BoatClass") & " - " & oRS("BoatName") & "</
option>"
oRS.MoveNext
Loop
Andyza [ Mo, 17 September 2007 14:14 ] [ ID #1822434 ]

Re: Still Not Resolved

Andyza wrote on 17 sep 2007 in microsoft.public.inetserver.asp.db:

> Do while not oRS.EOF
> response.Write "<option value='" & oRS("BoatName") & "'>"
> response.Write oRS("BoatClass") & " - " & oRS("BoatName") & "</
> option>"
> oRS.MoveNext
> Loop

I would write that like this:

<%
Do while not oRS.EOF
%>

<option value='<% = oRS("BoatName") %>'>
<% = oRS("BoatClass") %>-<% = oRS("BoatName") %>
</option>

<%
oRS.MoveNext
Loop
%>

Much less error prone for me at least.

[oRS("BoatName") shoud not contain an apostrophe, btw]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
exjxw.hannivoort [ Mo, 17 September 2007 17:09 ] [ ID #1822435 ]

Re: Still Not Resolved

Gazing into my crystal ball I observed "Evertjan."
<exjxw.hannivoort [at] interxnl.net> writing in news:Xns99AEAE807E270eejj99 [at]
194.109.133.242:

> Andyza wrote on 17 sep 2007 in microsoft.public.inetserver.asp.db:
>
>> Do while not oRS.EOF
>> response.Write "<option value='" & oRS("BoatName") & "'>"
>> response.Write oRS("BoatClass") & " - " & oRS("BoatName") & "</
>> option>"
>> oRS.MoveNext
>> Loop
>
> I would write that like this:
>
><%
> Do while not oRS.EOF
> %>
>
><option value='<% = oRS("BoatName") %>'>
><% = oRS("BoatClass") %>-<% = oRS("BoatName") %>
></option>
>
><%
> oRS.MoveNext
> Loop
> %>
>
> Much less error prone for me at least.
>
> [oRS("BoatName") shoud not contain an apostrophe, btw]
>

Even better for the user:

<select name="field">
<option value="">Select</option>
<% while not ors.EOF %>
<option value="<% = oRS("BoatName") %>" <%if trim(field) = trim(oRS
("BoatName")) then%>selected="selected"<%end if%>><% = oRS("BoatClass")
%>-<% = oRS("BoatName") %></option>
<% ors.movenext
wend
ors.close
set obs = nothing
%>
</select>


--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Adrienne Boswell [ Di, 18 September 2007 08:07 ] [ ID #1823276 ]

Re: Still Not Resolved

Adrienne Boswell wrote on 18 sep 2007 in
microsoft.public.inetserver.asp.db:

> <% ors.movenext
> wend
> ors.close
> set obs = nothing
> %>
>

ors = Oral Rehydration Salts

obs? [oops?] It is nothing. ;-)

More seriously:

I presume that,
if the end of the serverside page code execution is near,
the ASP engine will take care of such closing and nothinging
without any performance damage.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
exjxw.hannivoort [ Di, 18 September 2007 08:53 ] [ ID #1823277 ]
Webserver » microsoft.public.inetserver.asp.db » Still Not Resolved

Vorheriges Thema: Is it possible that OLEDB connection is not available on a PC?
Nächstes Thema: ASP Database error