-
Listbox Select to SQL
I want to select an item from a listbox on my asp page, which in turns I would like it to update an SQL query on the same page. Then refresh browser so that new data is displayed based on what's selected from the list box. Here's the code. Any more efficient way is appreciated. The listbox entry would go in the SQL statement where COST_DISCOPS is currently.
<%
<!--#include file="adovbs.inc"-->
Dim DBCONN
Dim RS
Dim SQL
Dim Listbox
SET DbConn = Server.CreateObject("ADODB.Connection")
Listboxid = Request.Form("MylistBox")
Set RS = Server.CreateObject("ADODB.RECORDSET")
DB2 = Session("DB2")
DBCONN.Open("DB2;")
SQL2 ="SELECT DISTINCT ENTITY FROM July03"
SQL ="SELECT * FROM July03 where entity = 'COST_DISCOPS' "
RS.Open SQL2, DBCONN
%>
<TABLE border=2>
<TR>
<TD><B>Entity</B></TD>
<TD><B>Account</B></TD>
<TD><B>Amount</B></TD>
</TR>
<%
Response.Write "<SELECT NAME=selListBox SIZE =10 MULTIPLE>"
do while not RS.EOF
Response.Write "<OPTION VALUE=" & RS("entity")
Response.Write ">" & RS("ENTITY") & "</OPTION>"
RS.MOVENEXT
LOOP
Response.Write "</select>"
RS.CLOSE
%>
<%
RS.Open SQL
Do While Not RS.EOF
Response.Write "<TR ><TD width =100>" & RS("ENTITY") & "</TD>"
Response.Write "<TD width = 75 >" & RS("Account") & "</TD>"
Response.Write "<TD align='right'>" & formatnumber(RS("Amount"),0) & "</TD>"
Response.Write vbcrlf