Display SQL Results
Display a page that allows you to type in a SQL Query statement, and display the results in HTML Table format.
The number of field parameters and field names are immaterial. It will display the results in an easy to read format. Great for customer reports.
The Code will not allow an Update or Delete query.
Original Author: Eugene
Inputs
You will have to provide the connection to your database. There are examples in the code.
Returns
An HTML Page
Code
<%
' Open Connection to the database
dim Connect
set Connect = Server.CreateObject("ADODB.Connection")
REM - Un-Rem one of the connect statements depending on your data
' connection method, and change the phyisical path if necessary
'1. ODBC
'strConn = "DSN=ASP-Forum; uid=;password=;"
'2. SQL-OLEDB
'strConn = "PROVIDER=SQLOLEDB; uid=;password=;Initial Catalog=ASPForum;"
'3. ADO-Access
'strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:inetpubwwwrootaspforumforum.mdb"
'4. OLE 4.0
'strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=d:inetpubwwwrootaspforumforum.mdb"
Connect.Open strConn
sSQL = request.form("Sequel")
%>
<%
if left(ucase(trim(sSQL)), 6) = "UPDATE" or left(ucase(trim(sSQL)), 6) = "DELETE" or left(ucase(trim(sSQL)), 4) = "DROP" then
%>
Function Not Allowed from this view
<%
elseif sSQL > "" then
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sSQL, Connect
flds = rs.Fields.Count
if not (rs.bof and rs.eof) then
%>
Searching for selected data...
<%
dim sColor(1)
toggle = 1
sColor(0) = ""
sColor(1) = "bgcolor=#eeeeee"
response.write "" & vbCrLf
"
response.write "" & vbCrLf "
For i = 0 To flds - 1
response.write "" & rs.Fields(i).Name & " "
Next
response.write vbCrLf & "
rs.movefirst
Do While Not rs.EOF
toggle = 1 - toggle
response.write "" & vbCrLf "
For i = 0 To flds - 1
response.write "" & rs.Fields(i).Value & " "
Next
response.write vbCrLf & "
rs.MoveNext
Loop
end if
rs.Close
Set rs = Nothing
response.write vbcrlf & "
end if
%>
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.