...

View Full Version : Drop Down list from database



Seanus
04-21-2006, 01:12 PM
HI guys,

I am starting to go a bit mad - please help. I have got a database with about 40 schoolnames that I am trying to display in a drop down but it only shows the first 20 or so records. I have been through it all about 100 times but don't know asp well enough to see where it is not working. I have pasted the code below and would like to thank you in advance:

<form action="send_email.asp" method=post>
<select name="schoolname">

<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rswedweb 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
Dim schoolcont

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Wedweb.mdb")

'Create an ADO recordset object
Set rswedweb = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
'strSQL = "select schoolcont.schoolname FROM schoolcont ORDER BY schoolname"
'strSQL = "select schoolcont.schoolname, schoolcont.supported, schoolcont.email FROM schoolcont where schoolcont.supported = 'Y' ORDER BY schoolname"
strSQL = "select * FROM schoolcont"

'Open the recordset with the SQL query
rswedweb.Open strSQL, adoCon

Do While not rswedweb.EOF
schoolname = rswedweb("schoolname")
if Not IsNull(schoolname) then %>


<%end if%>

<option value="<%Response.Write rswedweb("schoolname") & ""%></option>
<%Response.Write rswedweb ("schoolname")%>
<%rswedweb.MoveNext
Loop



'Reset server objects
rswedweb.Close
Set rswedweb = Nothing
Set adoCon = Nothing
%>
</select>
</form>
</td>

BaldEagle
04-23-2006, 01:24 AM
Make this change:


<option value="<%=rswedweb("schoolname")%>"><%=rswedweb("schoolname")%></option>
or

<option value="<%=schoolname%>"><%=schoolname%></option>

BaldEagle

Seanus
04-24-2006, 11:15 AM
Thanks a lot! This has worked. Much appreciated.

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum