<% Response.Buffer=True %> <% 'database startup code dim RS 'recordset object Set RS = Server.CreateObject("ADODB.Recordset") 'data source strings for drop down list dim dsnarray(2) dsnarray(0) = "MP3" dsnarray(1) = "Protfolio" dsnarray(2) = "ProductsDB" 'retrieve the form values sql = Request.Form("sql") 'the SQL statement clp = Request.Form("clp") 'the clipboard dsn = Request.Form("dsn") 'the data source string %> <html> <head> <title>SQL Test</title> <style> TD {font-size: smaller } </style> </head> <body bgcolor="#cecece"> <form action="sqltest.asp" method=POST> <table border=0 cellspacing=0> <tr><td><b>SQL Code</b></td><td><b>Clipboard</b></td></tr> <tr><td><textarea name="sql" rows="8" cols="50" wrap=soft><%=sql%></textarea></td> <td><textarea name="clp" rows="8" cols="30" wrap=soft><%=clp%></textarea> </td></tr> <tr><td colspan=2> <!-- using the drop down list of connect string --> <select name="dsn"> <% ' loop through the array of DSN's select the current one for i = LBound(dsnarray) to UBound(dsnarray) if dsnarray(i) = dsn then Response.Write("<option selected>" & dsnarray(i)) else Response.Write("<option>" & dsnarray(i)) end if next %> </select> </td></tr> <!-- this code allows you to test different connect strings --> <!-- <tr><td colspan=2><textarea name="dsn" rows="2" cols="80" wrap=soft><%=dsn%></textarea></td></tr> --> </table> <input type=submit> </form> <% Response.Flush 'for long winded queries, this will write out the response buffers %> <% if sql <> "" then ' execute the SQL if it's not empty RS.Open sql, dsn Response.Write("<table border=1 cellspacing=0>") if RS.State = 1 then 'if the recordset has rows 'show the column names Response.Write("<tr bgcolor=LightSteelBlue>") for each f in RS.Fields Response.Write("<td><b>" & f.Name & "</b></td>") next Response.Write("</tr>") 'show the rows do while not RS.EOF Response.Write("<tr bgcolor=White>") for each f in RS.Fields Response.Write("<td>" & f.Value & "</td>") next Response.Write("</tr>") RS.MoveNext loop else 'DML was performed Response.Write("<tr bgcolor=White><td><b>Command Completed Successfully</b></td></tr>") end if Response.Write("</table>") end if %> <% 'database clean up code Set RS = Nothing %> </body> </html>