PDA

View Full Version : Database connection issue


JustAsking
05-07-2003, 01:29 AM
When I have two dropdown boxes in the same using accessing a database, only the first dropdown box displays its values and the second does not. It probably has to do with accessing the recordset or connection string, but I'm not sure. Any suggestions.

I open a connection in a sub:


Sub OpenConnection() '''''''''''''''''''''''''''''
sConnString = "Driver={SQL Server};" & _
"Server=****;" & _
"Database=*****;" & _
"Uid=*******;" & _
"Pwd=*****"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sConnString

End Sub ''''''''''''''''''''''''''''''''''''''''''



<select name="requiredschool">
<%
Dim DisplayResults, rsSchool, sResult, school_value, school_name
DisplayResults = "SELECT school_name FROM NF_Results WHERE username = '" & username & "'"
Set rsSchool = Conn.Execute(DisplayResults)
sResult = RequestFormat(rsSchool.Fields("school_name").value)
Dim DisplaySchool
DisplaySchool = "SELECT * FROM NF_School"
Set rsSchool = Conn.Execute(DisplaySchool)
do while Not rsSchool.EOF
if rsSchool.Fields("school_name") = sResult then
Response.Write("<option value=" & rsSchool.Fields("school_value")& " selected>" & server.HTMLEncode(rsSchool.Fields("school_name")))
else
Response.Write("<option value=" & rsSchool.Fields("school_value")& ">" & server.HTMLEncode(rsSchool.Fields("school_name")))
end if
response.write("</option>")
rsSchool.MoveNext
loop
%>
</select>

'second dropdown box does not display values, is blank

<select name="requireddistrict">
<%
Dim DisplayDistrict, rsDistrict, dResult
DisplayResults = "SELECT disrict_name FROM NF_Results WHERE username = '" & username & "'"
Set rsDistrict = Conn.Execute(DisplayResults)
dResult = RequestFormat(rsDistrict.Fields("district_name").value)
DisplayDistrict = "SELECT * FROM NF_District"
Set rsDistrict = Conn.Execute(DisplayDistrict)
do while Not rsDistrict.EOF
if rsDistrict.Fields("district_name") = dResult then
Response.Write("<option value=" & rsDistrict.Fields("district_value")& " selected>" & server.HTMLEncode(rsDistrict.Fields("district_name")))
else
Response.Write("<option value=" & rsDistrict.Fields("district_value")& ">" & server.HTMLEncode(rsDistrict.Fields("district_name")))
end if
response.write("</option>")
rsDistrict.MoveNext
loop
%>

arnyinc
05-07-2003, 02:29 PM
I don't see anything wrong except for possibly missing the </select> for the second dropdown. Does looking at the HTML that is produced give any hints? I.e. are the <option> boxes being printed at all, but you don't see them in your browser.