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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a list box from a table

Status
Not open for further replies.

TomBarrand

Programmer
Aug 9, 2000
162
GB
I want to populate a list box with values from a column in a table. At the momment it just lists every value, so I get duplicates. How can I stop duplicates occurring. Some of my current code is below.

Thanks,

<%
Dim oRSs
Set oRSs=Server.CreateObject (&quot;ADODB.Recordset&quot;)
oRSs.Open &quot;table_name&quot;, &quot;DSN=dsnname;uid=;pwd=&quot;
oRSs.MoveFirst
%>
<form method=&quot;post&quot; ACTION=&quot;SOResults.asp&quot;>
<P><select name=&quot;Salesperson&quot; size=&quot;1&quot;>
<%
Do while not oRSs.eof
Response.Write &quot;<option value='&quot; & oRSs (&quot;salesRep&quot;) & &quot;'>&quot;
Response.Write oRSs (&quot;salesRep&quot;)
Response.Write &quot;</option>&quot;
oRSs.MoveNext
Loop
oRSs.Close
Set oRSs=nothing
%>
 
Use an SQL command to get the values from the table. You could do something like:

<%
Dim oRSs
Set oRSs=Server.CreateObject (&quot;ADODB.Recordset&quot;)
oRSs.Open &quot;SELECT DISTINCT salesRep from table_name&quot;, &quot;DSN=dsnname;uid=;pwd=&quot;
oRSs.MoveFirst
%>

The SELECT command will ensure that you only get unique values from the salesRep field.
Mise Le Meas,

Mighty :)
 
Someone'S already given you best option, but yeh SELECT DISTINCT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top