Click to See Complete Forum and Search --> : dynamic drop down box problem


stevem2004
12-10-2004, 06:31 AM
Hi,

I am using the following code to populate a drop down box, but it's not working. Can anyone tell me why?


<%
Dim strconn, conn, rs
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("database")
set conn = server.createobject("adodb.connection")
%>
<tr>
<td class="normal">System:</td>
<td><select name="system" class="normal">
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "table", Conn, 2, 2

Do While Not rs.eof
%>
<option value="<%=rs("system")%>"><%=rs("system")%></option>
<%
rs.movenext
Loop
%>
</select>
</td>
<%
rs.close
set rs = nothing
%>


Help would be appreciated.

TIA Steve

scragar
12-10-2004, 07:30 AM
what does it do(in way of an error or content it produces)

one thing you might want to try if you've updated it is checkking that the ASP is of a high enough version(so ASP knows how to interact with this particular kind of .mdb)

stevem2004
12-10-2004, 07:40 AM
This populates a drop down box with values that are stored in the Database.

scragar
12-10-2004, 07:49 AM
I meant what is it doing at the current time to indicat that it's not working. If it does populate them at the moment you wouldn't have posted it here.

stevem2004
12-10-2004, 08:01 AM
Sorry, nothing get displayed, it's just a blank dropdown box & there is nothing to select. No error message though, although not all of the pages loads.

scragar
12-10-2004, 08:06 AM
are you sure you're connecting to the database right? you seam to have info in strconn that's not actualy used for anything(although I've forgoten most of ASP I think you do need to use it for something in you conection...)

stevem2004
12-10-2004, 08:13 AM
strconn is defining the database, conn the connection??

There is nothing wrong with the connection to the database, this works for this page as all the data is being populated throughout the rest of the page, it's just the fact that I cannot get the dropdown to work, therefore I belive the problem is how I have tried to get the information from the database in the select or option tags.

stevem2004
12-10-2004, 10:22 AM
I have made some changes & now I get a drop down box with 15 items, unfortunately they are all called the same name. I have 15 items in the database, if the first one is Marcus, then I have 15 choices all called Marcus :confused:

I am using the following code

<%
Dim strconn, conn, rs, strSystem
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("../database/.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
strSQL = "SELECT * FROM system;"
set rs = server.createobject("adodb.recordset")
rs.open strSQL, conn, 3, 3

if rs.EOF and rs.BOF then
response.write ("<p class=""normalbold"">Database Empty.")
response.end
end if

strSystem = rs("system")

%>
<tr>
<td class="normal">System:</td>
<td><select name="system" class="form">
<%
Do While Not rs.eof
%>
<option value="system"><%=strSystem%></option>
<%
rs.movenext
Loop
%>
</select>


Does anybody know what I'm doing wrong?? It would seem the Loop is not working?? but I'm not sure...

Please help

russell
12-10-2004, 01:00 PM
change this

strSystem = rs("system")

%>
<tr>
<td class="normal">System:</td>
<td><select name="system" class="form">
<%
Do While Not rs.eof
%>
<option value="system"><%=strSystem%></option>
<%
rs.movenext
Loop
%>

To this

%>
<tr>
<td class="normal">System:</td>
<td><select name="system" class="form">
<%
Do While Not rs.eof
strSystem = rs("system")
%>
<option value="system"><%=strSystem%></option>
<%
rs.movenext
Loop
%>

stevem2004
12-14-2004, 05:03 AM
Many Thanks russell, that did it.