<%@ Language=VBScript %> <% option explicit dim sql sql = request.form("sql") if sql = "" then sql = "select * from students;" sql = trim(sql) %> Roll Your Own SQL

SQL Query via a Web Interface

Queries must use single quotes for strings e.g. select * from students where lastname = 'Smith';


<% on error resume next 'this example looks at pulling information out of the database dim conn,rs dim fname,connstr Set conn = Server.CreateObject("ADODB.Connection") fname = server.mappath("students.mdb") connstr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & fname conn.open connstr,"","" Set rs = Server.CreateObject("ADODB.Recordset") if instr(ucase(sql),"SELECT") = 1 then 'sql = replace(sql,"'","''") response.write("

Query is... " & sql & "

") rs.Open sql, conn, 1, 1 if err.description = "" then dim fcount 'following pulls the number of fields out of the recordset... fcount = rs.fields.count response.write ("

Total Fields: " & fcount) dim rcount 'following gets the number of records... rcount = rs.recordcount 'now put the info in the presentation... response.write ("

Total Records: " & rcount) dim i do while not rs.eof response.write ("

--------------New Record------------
") 'here we use the recordcount in for-next loop 'note that arrays tend to be 0 referenced for i = 0 to rs.fields.count - 1 response.write (rs.fields(i).name) response.write (" --- ") Response.Write (rs.fields(i).value) response.write ("
") 'Close the loop iterating records next rs.MoveNext loop else response.write("Error in the query: " & err.description & "") end if rs.Close else if sql <> "" then response.write("

You do not have a Select statement!

") end if set rs = Nothing set conn = Nothing %>